kubernetes Node節點部署(四)

1、部署kubelet

1.一、二進制包準備 將軟件包從linux-node1複製到linux-node2中去node

[root@linux-node1 ~]# cd /usr/local/src/kubernetes/server/bin/ [root@linux-node1 bin]# cp kubelet kube-proxy /opt/kubernetes/bin/ [root@linux-node1 bin]# scp kubelet kube-proxy 192.168.56.12:/opt/kubernetes/bin/ [root@linux-node1 bin]# scp kubelet kube-proxy 192.168.56.13:/opt/kubernetes/bin/

1.二、建立角色綁定linux

[root@linux-node1 ~]# kubectl create clusterrolebinding kubelet-bootstrap --clusterrole=system:node-bootstrapper --user=kubelet-bootstrap clusterrolebinding "kubelet-bootstrap" created

1.三、建立 kubelet bootstrapping kubeconfig 文件 設置集羣參數git

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

 

1.四、設置客戶端認證參數github

[root@linux ssl]# kubectl config set-credentials kubelet-bootstrap \ >    --token=d192434528f7576911ac9d333a982d93 \ >    --kubeconfig=bootstrap.kubeconfig User "kubelet-bootstrap" set.

 

注:d192434528f7576911ac9d333a982d93 根據實際狀況填寫,能夠經過cat /opt/kubernetes/ssl/bootstrap-token.csv 查看docker

1.五、設置上下文參數json

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

 

1.六、選擇默認上下文bootstrap

[root@linux-node1 ~]# kubectl config use-context default --kubeconfig=bootstrap.kubeconfig Switched to context "default". [root@linux-node1 kubernetes]# cp bootstrap.kubeconfig /opt/kubernetes/cfg [root@linux-node1 kubernetes]# scp bootstrap.kubeconfig 192.168.56.12:/opt/kubernetes/cfg [root@linux-node1 kubernetes]# scp bootstrap.kubeconfig 192.168.56.13:/opt/kubernetes/cfg

 

1.七、部署kubelet 1.設置CNI支持(全部節點執行)vim

[root@linux-node2 ~]# mkdir -p /etc/cni/net.d [root@linux-node2 ~]# vim /etc/cni/net.d/10-default.conf { "name": "flannel", "type": "flannel", "delegate": { "bridge": "docker0", "isDefaultGateway": true, "mtu": 1400 } }

[root@linux ssl]# scp /etc/cni/net.d/10-default.conf 192.168.56.12:/etc/cni/net.d/
[root@linux ssl]# scp /etc/cni/net.d/10-default.conf 192.168.56.13:/etc/cni/net.d/app

 

 

1.八、建立kubelet目錄(全部節點執行)dom

[root@linux-node2 ~]# mkdir /var/lib/kubelet

 

1.九、建立kubelet服務配置(每一個節點執行)

[root@k8s-node2 ~]# 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=/opt/kubernetes/bin/kubelet \ --address=192.168.56.12 \ --hostname-override=192.168.56.12 \ --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

 

注:修改每一個節點對應的ip

1.10.啓動Kubelet

[root@linux-node2 ~]# systemctl daemon-reload [root@linux-node2 ~]# systemctl enable kubelet [root@linux-node2 ~]# systemctl start kubelet

 

只在node節點上啓動  ,master不用啓動

1.十一、查看csr請求 注意是在linux-node1上執行。

[root@linux ssl]# kubectl get csr NAME AGE REQUESTOR CONDITION node-csr-JvaaEZ211tAksrMkeWzInQroN1O4s8rKqqwT9RC4ubA   1m        kubelet-bootstrap Pending node-csr-lcMGqB_XHi4lQIKZr2oRdseQ4_IVn-lZx3_SmLLd1i0   1m        kubelet-bootstrap   Pending

 

1.十二、批准kubelet 的 TLS 證書請求

kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| xargs kubectl certificate approve

執行完畢後,查看節點狀態已是Ready的狀態了

[root@linux ssl]# kubectl get node NAME STATUS ROLES AGE VERSION 192.168.56.12   Ready     <none>    3m        v1.10.1
192.168.56.13   Ready     <none>    3m        v1.10.1

 

2、Kubernetes Proxy

2.一、配置kube-proxy使用LVS(每一個節點安裝)

yum install -y ipvsadm ipset conntrack

 

2.二、在master節點上建立 kube-proxy 證書請求

[root@linux-node1 ~]# cd /usr/local/src/ssl/ [root@linux-node1 ~]# 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" } ] }

 

2.三、生成證書

[root@linux-node1~]# cfssl gencert -ca=/opt/kubernetes/ssl/ca.pem \ -ca-key=/opt/kubernetes/ssl/ca-key.pem \ -config=/opt/kubernetes/ssl/ca-config.json \ -profile=kubernetes  kube-proxy-csr.json | cfssljson -bare kube-proxy

 

2.四、分發證書到全部Node節點

[root@linux-node1 ssl]# cp kube-proxy*.pem /opt/kubernetes/ssl/ [root@linux-node1 ssl]# scp kube-proxy*.pem 192.168.56.12:/opt/kubernetes/ssl/ [root@linux-node1 ssl]# scp kube-proxy*.pem 192.168.56.13:/opt/kubernetes/ssl/

 

2.五、建立kube-proxy配置文件

[root@linux-node2 ~]# kubectl config set-cluster kubernetes \ --certificate-authority=/opt/kubernetes/ssl/ca.pem \ --embed-certs=true \ --server=https://192.168.56.11:6443 \
   --kubeconfig=kube-proxy.kubeconfig Cluster "kubernetes" set. [root@linux-node2 ~]# kubectl config set-credentials kube-proxy \ --client-certificate=/opt/kubernetes/ssl/kube-proxy.pem \ --client-key=/opt/kubernetes/ssl/kube-proxy-key.pem \ --embed-certs=true \ --kubeconfig=kube-proxy.kubeconfig User "kube-proxy" set. [root@linux-node2 ~]# kubectl config set-context default \ --cluster=kubernetes \ --user=kube-proxy \ --kubeconfig=kube-proxy.kubeconfig Context "default" created. [root@linux-node2 ~]# kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig Switched to context "default".

 

2.六、分發kubeconfig配置文件

[root@linux-node1 ssl]# cp kube-proxy.kubeconfig /opt/kubernetes/cfg/ [root@linux-node1 ~]# scp kube-proxy.kubeconfig 192.168.56.12:/opt/kubernetes/cfg/ [root@linux-node1 ~]# scp kube-proxy.kubeconfig 192.168.56.13:/opt/kubernetes/cfg/

 

2.七、建立kube-proxy服務配置(每一個節點執行)

[root@linux-node2 bin]# mkdir /var/lib/kube-proxy [root@k8s-node2 ~]# 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=/opt/kubernetes/bin/kube-proxy \ --bind-address=192.168.56.12 \ --hostname-override=192.168.56.12 \ --kubeconfig=/opt/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=/opt/kubernetes/log Restart=on-failure RestartSec=5 LimitNOFILE=65536 [Install] WantedBy=multi-user.target

 

注:修改對應節點的ip

2.八、啓動

[root@linux-node2 ~]# systemctl daemon-reload [root@linux-node2 ~]# systemctl enable kube-proxy [root@linux-node2 ~]# systemctl start kube-proxy

2.九、檢查lvs狀態

[root@linux ssl]# 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 persistent 10800
  -> 192.168.56.11:6443           Masq    1      0          0

若是你在兩臺實驗機器都安裝了kubelet和proxy服務,使用下面的命令能夠檢查狀態:

[root@linux ssl]# kubectl get node NAME STATUS ROLES AGE VERSION 192.168.56.12   Ready     <none>    22m       v1.10.1
192.168.56.13   Ready     <none>    22m       v1.10.1
相關文章
相關標籤/搜索