kubernetes添加刪除重啟節點
阿新 • • 發佈:2019-04-02
... ont server 4.0 ide -m nat form fyi
1.添加節點
(master)查看目前節點
[[email protected] ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master Ready master 153m v1.14.0 k8s-node1 Ready <none> 117m v1.14.0 [[email protected]-master ~]#
clone k8s在執行kubeadm init命令前時的狀態機器,修改ip,修改主機名
node2上操作
hostnamectl set-hostname k8s-node2
reboot
添加k8s-node2節點(node2上操作)
[[email protected]k8s-node2 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward [[email protected]k8s-node2 ~]# kubeadm join 192.168.111.130:6443 --token ymtl8s.933t59qfezi9gjcq --discovery-token-ca-cert-hash sha256:7816d0b2572e6c569ed8e63ece15a7a08d06ed3fc89698245bf2aaa6acc345d7 [preflight] Running pre-flight checks [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with ‘kubectl -n kube-system get cm kubeadm-config -oyaml‘ [kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.14" ConfigMap in the kube-system namespace [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Activating the kubelet service [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap... This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details.
Run ‘kubectl get nodes‘ on the control-plane to see this node join the cluster.
master上查看是否成功添加
[[email protected]k8s-master ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master Ready master 178m v1.14.0 k8s-node1 Ready <none> 142m v1.14.0 k8s-node2 Ready <none> 27s v1.14.0
[email protected] ~]# kubectl get po --all-namespaces -o wide ##-o查看pod運行在那個node上,--namespace=kube-system查看系統pod NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES kube-system coredns-fb8b8dccf-ltlx4 1/1 Running 0 3h12m 10.244.0.4 k8s-master <none> <none> kube-system coredns-fb8b8dccf-q949f 1/1 Running 0 3h12m 10.244.0.5 k8s-master <none> <none> kube-system etcd-k8s-master 1/1 Running 2 3h11m 192.168.111.130 k8s-master <none> <none> kube-system kube-apiserver-k8s-master 1/1 Running 2 3h12m 192.168.111.130 k8s-master <none> <none> kube-system kube-controller-manager-k8s-master 1/1 Running 2 3h11m 192.168.111.130 k8s-master <none> <none> kube-system kube-flannel-ds-amd64-2gr2v 1/1 Running 0 177m 192.168.111.130 k8s-master <none> <none> kube-system kube-flannel-ds-amd64-bsrkx 1/1 Running 0 157m 192.168.111.131 k8s-node1 <none> <none> kube-system kube-flannel-ds-amd64-xdg5p 1/1 Running 0 15m 192.168.111.132 k8s-node2 <none> <none> kube-system kube-proxy-2mj4q 1/1 Running 0 157m 192.168.111.131 k8s-node1 <none> <none> kube-system kube-proxy-ffd8s 1/1 Running 0 15m 192.168.111.132 k8s-node2 <none> <none> kube-system kube-proxy-qp5k7 1/1 Running 0 3h12m 192.168.111.130 k8s-master <none> <none> kube-system kube-scheduler-k8s-master 1/1 Running 2 3h12m 192.168.111.130 k8s-master <none> <none> [[email protected]-master ~]#
2.刪除節點
master上執行
kubectl drain k8s-node2 --delete-local-data --force --ignore-daemonsets
kubectl delete node k8s-node2
node2上執行
kubeadm reset
3.節點重啟
無需特別操作,保證節點kubelet是開機啟動就行
systemctl enable kubelet
systemctl restart kubelet 或者 service kubelet start
kubernetes添加刪除重啟節點