Kubernetes deployment: Node deployment

Nodes only need to install kubelet service, and all node s need to install Kube proxy

Deploy kubelet

1. Binary package preparation
Copy the package from to all node s.

[root@node-01 ~]# cd /usr/local/src/kubernetes/server/bin/
[root@node-01 bin]# for n in `seq 204 206`;do scp kubelet 10.31.90.$n:/data/kubernetes/bin/ ;done
[root@node-01 bin]# for n in `seq 201 206`;do scp  kube-proxy 10.31.90.$n:/data/kubernetes/bin/ ;done

2. Create role binding

[root@node-01 ~]# kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap
clusterrolebinding.rbac.authorization.k8s.io/kubelet-bootstrap created

3. Create the kubelet bootstrapping kubeconfig file
Set cluster parameters

[root@node-01 ~]# kubectl config set-cluster kubernetes \
   --certificate-authority=/data/kubernetes/ssl/ca.pem \
   --embed-certs=true \
   --server=https://10.31.90.200:6443 \
   --kubeconfig=bootstrap.kubeconfig
Cluster "kubernetes" set.

Set the client authentication parameter. The token should use the previous one

[root@node-01 ~]# kubectl config set-credentials kubelet-bootstrap \
   --token=cf25becebf64e3fffd7f3890a60ac16d \
   --kubeconfig=bootstrap.kubeconfig   
User "kubelet-bootstrap" set.

Set context parameters

[root@node-01 ~]# kubectl config set-context default \
   --cluster=kubernetes \
   --user=kubelet-bootstrap \
   --kubeconfig=bootstrap.kubeconfig
Context "default" created.

Select default context

[root@node-01 ~]# kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
Switched to context "default".
#Copy to 3 node s
for n in `seq 204 206`;do scp bootstrap.kubeconfig 10.31.90.$n:/data/kubernetes/cfg/;done

Deploy kubelet(node node)

  1. Set up CNI support (all nodes)
    [root@node-01 ~]# mkdir -p /etc/cni/net.d
    [root@node-01 ~]# cat >>/etc/cni/net.d/10-default.conf<<EOF
    {
        "name": "flannel",
        "type": "flannel",
        "delegate": {
            "bridge": "docker0",
            "isDefaultGateway": true,
            "mtu": 1400
        }
    }
    EOF

2. Create kubelet directory

[root@node-04 ~]# mkdir /var/lib/kubelet

3. Create kubelet service configuration

[root@node-04 ~]# vim /usr/lib/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service

[Service]
WorkingDirectory=/var/lib/kubelet
ExecStart=/data/kubernetes/bin/kubelet \
  --address=10.31.90.204 \
  --hostname-override=10.31.90.204 \
  --pod-infra-container-image=mirrorgooglecontainers/pause-amd64:3.0 \
  --experimental-bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \
  --kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \
  --cert-dir=/opt/kubernetes/ssl \
  --network-plugin=cni \
  --cni-conf-dir=/etc/cni/net.d \
  --cni-bin-dir=/opt/kubernetes/bin/cni \
  --cluster-dns=10.1.0.2 \
  --cluster-domain=cluster.local. \
  --hairpin-mode hairpin-veth \
  --allow-privileged=true \
  --fail-swap-on=false \
  --logtostderr=true \
  --v=2 \
  --logtostderr=false \
  --log-dir=/opt/kubernetes/log
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

4. Start Kubelet

[root@node-04 ~]# systemctl daemon-reload
[root@node-04 ~]# systemctl enable kubelet
[root@node-04 ~]# systemctl start kubelet

5. View service status

[root@node-04 kubernetes]# systemctl status kubelet

6. View csr request
Note that it is executed on linux-node1.

[root@node-01 ssl]# kubectl get csr
NAME                                                   AGE       REQUESTOR           CONDITION
node-csr-NqH7J1OuDM_jGtQM_VuABiBcAqgDlT_MfJiVS_qWCbg   1m        kubelet-bootstrap   Pending
node-csr-jy10bYvow5hYQ2sKWfCuBlUNIPit54dhQfzRUd5E6dc   4m        kubelet-bootstrap   Pending
node-csr-zPPE5g4d1PtbKo-lQWNNC0bbngttC2bdZtwqBBvjrVM   1m        kubelet-bootstrap   Pending

7. Approve the TLS certificate request of kubelet

[root@node-01 ~]# kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| xargs kubectl certificate approve

After execution, check whether the node status is Ready

[root@node-01 ~]# kubectl get csr
NAME                                                   AGE       REQUESTOR           CONDITION
node-csr-NqH7J1OuDM_jGtQM_VuABiBcAqgDlT_MfJiVS_qWCbg   1m        kubelet-bootstrap   Approved,Issued
node-csr-jy10bYvow5hYQ2sKWfCuBlUNIPit54dhQfzRUd5E6dc   5m        kubelet-bootstrap   Approved,Issued
node-csr-zPPE5g4d1PtbKo-lQWNNC0bbngttC2bdZtwqBBvjrVM   2m        kubelet-bootstrap   Approved,Issued

Deploy Kubernetes Proxy

Kube proxy master and node nodes are installed
1. Configure Kube proxy to use LVS

[root@node-01 ~]# yum install -y ipvsadm ipset conntrack

2. Create a Kube proxy certificate request

[root@node-01 ssl]# cd /usr/local/src/ssl/
[root@node-01 ssl]# vim kube-proxy-csr.json
{
  "CN": "system:kube-proxy",
  "hosts": [],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}

3. Generate certificate

[root@node-01 ssl]# cfssl gencert -ca=/data/kubernetes/ssl/ca.pem \
   -ca-key=/data/kubernetes/ssl/ca-key.pem \
   -config=/data/kubernetes/ssl/ca-config.json \
   -profile=kubernetes  kube-proxy-csr.json | cfssljson -bare kube-proxy

4. Distribute certificates to all node nodes

[root@node-01 ssl]# for n in `seq 201 206`;do scp kube-proxy*.pem root@10.31.90.$n:/data/kubernetes/ssl;done

5. Create the Kube proxy configuration file

[root@node-01 ~]# kubectl config set-cluster kubernetes \
   --certificate-authority=/data/kubernetes/ssl/ca.pem \
   --embed-certs=true \
   --server=https://10.31.90.200:6443 \
   --kubeconfig=kube-proxy.kubeconfig
Cluster "kubernetes" set.

[root@node-01 ~]# kubectl config set-credentials kube-proxy \
   --client-certificate=/data/kubernetes/ssl/kube-proxy.pem \
   --client-key=/data/kubernetes/ssl/kube-proxy-key.pem \
   --embed-certs=true \
   --kubeconfig=kube-proxy.kubeconfig
User "kube-proxy" set.

[root@node-01 ~]# kubectl config set-context default \
   --cluster=kubernetes \
   --user=kube-proxy \
   --kubeconfig=kube-proxy.kubeconfig
Context "default" created.

[root@node-01 ~]# kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
Switched to context "default".

6. Distribute the kubeconfig configuration file

[root@node-01 ssl]# for n in `seq 201 206 `;do scp kube-proxy.kubeconfig 10.31.90.$n:/data/kubernetes/cfg/;done   

7. Create Kube proxy service configuration

[root@node-04 ~]# mkdir /var/lib/kube-proxy

[root@node-04 ~]# vim /usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target

[Service]
WorkingDirectory=/var/lib/kube-proxy
ExecStart=/data/kubernetes/bin/kube-proxy \
  --bind-address=10.31.90.204 \
  --hostname-override=10.31.90.204 \
  --kubeconfig=/data/kubernetes/cfg/kube-proxy.kubeconfig \
  --masquerade-all \
  --feature-gates=SupportIPVSProxyMode=true \
  --proxy-mode=ipvs \
  --ipvs-min-sync-period=5s \
  --ipvs-sync-period=5s \
  --ipvs-scheduler=rr \
  --logtostderr=true \
  --v=2 \
  --logtostderr=false \
  --log-dir=/data/kubernetes/log

Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

8.start-up Kubernetes Proxy
[root@node-04 ~]# systemctl daemon-reload
[root@node-04 ~]# systemctl enable kube-proxy
[root@node-04 ~]# systemctl start kube-proxy

9. View service status
View Kube proxy service status

[root@node-04 scripts]# systemctl status kube-proxy

//Check LVS status
[root@node-04 ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.1.0.1:443 rr
  -> 10.31.90.201:6443            Masq    1      0          0  

If both kubelet and proxy services are installed, use the following command to check the status:

[root@node-01 ~]# kubectl get node
NAME           STATUS    ROLES     AGE       VERSION
10.31.90.204   Ready     <none>    40m       v1.11.5
10.31.90.205   Ready     <none>    40m       v1.11.5
10.31.90.206   Ready     <none>    40m       v1.11.5

Please deploy node-05 and node-06 by yourself.
In the future, all the installation documents will be updated. If you think I wrote well, I hope you will pay more attention to it. Thank you very much!

Keywords: Kubernetes kubelet SSL vim

Added by gyoung on Wed, 04 Dec 2019 16:42:47 +0200