#扩容--前提基础软件准备就绪,docker,flannel,kube-proxy,kubelet,coredns等准备就绪[root@master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 3h56m v1.13.4
node01 Ready <none> 3h53m v1.13.4
#当前的token已经无效超过了24个小时[root@master ~]# kubeadm token list
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
05txgd.zd1kd5avee64leiv <invalid> 2020-04-01T12:52:32+08:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token
#创建新的token,TTL为23小时[root@master ~]# kubeadm token create
avvx3t.1rb388d69211v42e
[root@master ~]# kubeadm token list
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
05txgd.zd1kd5avee64leiv <invalid> 2020-04-01T12:52:32+08:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token
avvx3t.1rb388d69211v42e 23h 2020-06-09T09:27:10+08:00 authentication,signing <none> system:bootstrappers:kubeadm:default-node-token
#查看hash[root@master ~]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
dbd5573750f525e3d7ffdf03fc9436c63e1901c590589fadbb3f9e98feae480f
#新增节点执行(node02)[root@node02 ~]# kubeadm join 192.168.100.2:6443 --token avvx3t.1rb388d69211v42e --discovery-token-ca-cert-hash sha256:dbd5573750f525e3d7ffdf03fc9436c63e1901c590589fadbb3f9e98feae480f --ignore-preflight-errors=Swap[preflight] Running pre-flight checks[WARNING Swap]: running with swap on is not supported. Please disable swap
[discovery] Trying to connect to API Server "192.168.100.2:6443"[discovery] Created cluster-info discovery client, requesting info from "https://192.168.100.2:6443"[discovery] Requesting info from "https://192.168.100.2:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.100.2:6443"[discovery] Successfully established connection with API Server "192.168.100.2:6443"[join] Reading configuration from the cluster...
[join] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.13" 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[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "node02" as an annotationThis 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 master to see this node join the cluster.
#新增节点成功加入[root@master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 68d v1.13.4
node01 Ready <none> 68d v1.13.4
node02 Ready <none> 2m19s v1.13.4
总结:
扩容:新增节点的基础软件包准备好,并成功运行起来加入集群主要用到kubeadm join ,hash值和token
缩容:kubectl drain node ,使该节点不可调用,排干并驱逐现有节点的pod资源,并调度至其他节点