4.部署kuberntes node

ArcherBrian發表於2024-07-16

4.部署kuberntes node

[N1,N2,N3]新增Yum源

移除可能存在的元件

yum remove docker docker-common docker-selinux docker-engine

安裝一些依賴

yum install -y yum-utils device-mapper-persistent-data lvm2

配置Docker CE 源

wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

配置Kubernetes源

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=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

建立快取

yum makecache fast

[N1,N2,N3]安裝元件

kubeadm:叢集部署工具
kubectl:叢集管理工具
kubelet:叢集引擎
docker-ce:容器驅動

yum -y install docker-ce kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0

[N1,N2,N3]新增docker配置

在國內可以加速映象下載速度

mkdir /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
        "max-size": "100m",
        "max-file": "10"
  },
  "oom-score-adjust": -1000,
  "live-restore": true
}
EOF

[N1,N2,N3]啟動服務

啟動並配置開機自啟動

systemctl start docker kubelet
systemctl enable docker kubelet
INFO:
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

[N1,N2,N3]手動下載映象,加速叢集初始化

KUBE_VERSION=v1.15.0
KUBE_PAUSE_VERSION=3.1
  
GCR_URL=k8s.gcr.io
ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers
  
images=(kube-proxy:${KUBE_VERSION}
pause:${KUBE_PAUSE_VERSION})
  
  
for imageName in ${images[@]} ; do
  docker pull $ALIYUN_URL/$imageName
  docker tag  $ALIYUN_URL/$imageName $GCR_URL/$imageName
  docker rmi $ALIYUN_URL/$imageName
done

[N1,N2,N3]加入叢集

此命令在初始化Master叢集時有記錄

kubeadm join 192.168.83.3:6443 --token mpzs9m.oec6ixeesemzbxle \
    --discovery-token-ca-cert-hash sha256:7c05c8001693061902d6f20947fbc60c1b6a12e9ded449e6c59a71e6448fac5d

如果找不到了用上面的命令或者Token如果過期,在master節點執行即可

kubeadm token create --print-join-command

在Master節點檢視node節點狀態

kubectl get node

以下為輸出

NAME                    STATUS   ROLES    AGE   VERSION
k8s-test-master-1       Ready    master   73m   v1.15.0
k8s-test-master-2       Ready    master   68m   v1.15.0
k8s-test-master-3       Ready    master   67m   v1.15.0
k8s-test-node-1         Ready    <none>   75s   v1.15.0 #狀態為Ready即為成功加入叢集
k8s-test-node-2         Ready    <none>   63s   v1.15.0 #狀態為Ready即為成功加入叢集
k8s-test-node-3         Ready    <none>   59s   v1.15.0 #狀態為Ready即為成功加入叢集

相關文章