记录一次新节点加入K8S集群

新节点初始化 安装docker kubelet kubeadm(指定版本)
#先查看当前集群docker版本
[root@lecode-k8s-master manifests]# docker version
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.39
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:49:57 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          18.09.9
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11.13
  Git commit:       039a7df
  Built:            Wed Sep  4 16:22:32 2019
  OS/Arch:          linux/amd64
  Experimental:     false

#可以看到这里版本是20.10.14,新节点安装相同版本docker
[root@lecode-dev123 ~]# yum install docker-ce-20.10.14-3.el7 -y
#启动docker
systemctl enable docker && systemctl start docker

#配置镜像下载加速器
[root@lecode-dev123 ~]# cat /etc/docker/daemon.json 
{"insecure-registries": ["36.133.91.100:8090"],
  "registry-mirrors": ["http://hub-mirror.c.163.com", "http://f1361db2.m.daocloud.io"],
  "data-root": "/data/docker",
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": { "max-size": "100m"
  },
  "storage-driver": "overlay2"
}

#重启docker
systemctl daemon-reload
systemctl restart docker
docker info

#添加K8S源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

#安装kubeadm kubelet,注意版本,在集群使用kubectl version查看版本,指定相同版本新节点安装
yum install -y kubelet-1.16.0 kubeadm-1.16.0
systemctl enable kubelet

#在master节点查询加入节点的命令
[root@lecode-k8s-master manifests]# kubeadm token create --print-join-command
kubeadm join 192.168.1.11:6443 --token sqo8w7.s8plezzr9py2opcf     --discovery-token-ca-cert-hash sha256:b7465ee6c96240b9063a090b1c66be5264f06a38e3ac7dc1e428b4d62fce54ef 

#新节点加入集群
[root@lecode-dev123 ~]# kubeadm join 192.168.1.11:6443 --token sqo8w7.s8plezzr9py2opcf     --discovery-token-ca-cert-hash sha256:b7465ee6c96240b9063a090b1c66be5264f06a38e3ac7dc1e428b4d62fce54ef
[preflight] Running pre-flight checks
	[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.14. Latest validated version: 18.09
	[WARNING Hostname]: hostname "lecode-dev123" could not be reached
	[WARNING Hostname]: hostname "lecode-dev123": lookup lecode-dev123 on 211.136.17.107:53: no such host
[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.16" 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.

#查看集群信息
[root@lecode-k8s-master manifests]# kubectl get node
NAME              STATUS     ROLES    AGE    VERSION
k8s-master        Ready      master   209d   v1.16.0
lecode-dev-001    Ready      <none>   208d   v1.16.0
lecode-dev-002    Ready      <none>   208d   v1.16.0
lecode-dev123     NotReady   <none>   7s     v1.16.0
lecode-test-001   Ready      <none>   208d   v1.16.0
lecode-test-002   Ready      <none>   208d   v1.16.0

#等待网络插件安装
[root@lecode-k8s-master project-dep-yaml]# kubectl get node
NAME              STATUS   ROLES    AGE     VERSION
k8s-master        Ready    master   209d    v1.16.0
lecode-dev-001    Ready    <none>   208d    v1.16.0
lecode-dev-002    Ready    <none>   208d    v1.16.0
lecode-dev123     Ready    <none>   2m39s   v1.16.0
lecode-test-001   Ready    <none>   208d    v1.16.0
lecode-test-002   Ready    <none>   208d    v1.16.0

posted @ 2022-11-02 10:22  安生丶  阅读(168)  评论(0编辑  收藏  举报