在kubernetes中,从1.24版本开始,抛弃了docker,选择了containerd,containerd是从docker项目中分离出来的,所以底层还是和docker一样,这里就不过多的介绍docker和containerd的区别了,但是部署的时候有点区别的是在部署的时候把docker替换成containerd即可,下面看一下我的部署方式。主要参考:https://www.wulaoer.org/?p=2643
我这里前期准备就不做了,直接安装containerd,containerd安装成功之后,后面的就都一样了。
yum install containerd jq -y containerd config default > /etc/containerd/config.toml systemctl enable --now containerd systemctl restart containerd
containerd安装好之后后面的就都一样了,需要在每个节点上都安装一下kubelet kubeadm kubectl,这里同样注意版本的问题,
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [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 install -y --nogpgcheck kubelet kubeadm kubectl $ yum install -y kubelet-1.24.1 kubeadm-1.24.1 kubectl-1.24.1 #可以使用下面的命令查看仓库中软件的版本 $ yum --showduplicates list kubectl #如果已经安装可以使用kubectl version查看版本 $ systemctl start kubelet $ systemctl enable kubelet
所有节点安装成功之后,需要在master节点进行初始化kubernetes集群,这里注意初始化的时候一定要注意kubernetes的版本问题。
kubeadm init \ --apiserver-advertise-address=10.211.55.11 \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version v1.24.1 \ --service-cidr=10.96.0.0/12 \ --pod-network-cidr=10.244.0.0/16 .............................................. Your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ Then you can join any number of worker nodes by running the following on each as root: kubeadm join 10.211.55.11:6443 --token 33rpzd.8r7ahl337rvmzait \ --discovery-token-ca-cert-hash sha256:966ee1b5539555699372c9ab7d89f404fb38fb9556b6cbcf1f4c058ee79518ff
到这里说明master节点初始化成功了,要想访问集群还需要在master节点配置kubernetes连接信息,上面已经有提示了。
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
直接复制粘贴即可,另外在其他节点执行
kubeadm join 10.211.55.11:6443 --token 33rpzd.8r7ahl337rvmzait \ --discovery-token-ca-cert-hash sha256:966ee1b5539555699372c9ab7d89f404fb38fb9556b6cbcf1f4c058ee79518ff
这里注意,这个token有效期是24小时,过了24小时需要重新获取使用
kubeadm token create --print-join-command
即可获取,这样整个集群就搭建完了,但是还有网络插件没有安装,同样参考上面的即可。
curl https://docs.projectcalico.org/manifests/calico.yaml -O #k8s-v1.20支持的最新版calico是v3.20 #故正确获取calico的yaml文件应该用: #https://docs.projectcalico.org/archive/v3.20/manifests/calico.yaml kubectl apply -f calico.yaml [root@k8s-master ~]# kubectl get node NAME STATUS ROLES AGE VERSION k8s-master Ready control-plane 60m v1.24.1 k8s-node01 Ready <none> 29m v1.24.1 k8s-node02 Ready <none> 28m v1.24.1 [root@k8s-master ~]# kubectl get pod -A NAMESPACE NAME READY STATUS RESTARTS AGE kube-system calico-kube-controllers-7fc4577899-885s2 1/1 Running 4 (2m59s ago) 7m34s kube-system calico-node-7hfnm 1/1 Running 0 45m kube-system calico-node-7pv29 1/1 Running 0 45m kube-system calico-node-fbg6m 1/1 Running 0 45m kube-system coredns-74586cf9b6-h9rd5 1/1 Running 0 11m kube-system coredns-74586cf9b6-rlrvr 1/1 Running 1 (3m39s ago) 7m34s kube-system etcd-k8s-master 1/1 Running 0 59m kube-system kube-apiserver-k8s-master 1/1 Running 0 59m kube-system kube-controller-manager-k8s-master 1/1 Running 0 59m kube-system kube-proxy-2mfcq 1/1 Running 0 59m kube-system kube-proxy-gnf7s 1/1 Running 0 45m kube-system kube-proxy-qs4v8 1/1 Running 0 53m kube-system kube-scheduler-k8s-master 1/1 Running 0 59m
至此,1.24.1版本的kubernetes就安装好了,另外如果是1.24之前的版本升级到1.24+的版本就需要去掉原来的docker替换成containerd,这样整个集群才正常,如果在部署的过程中出现异常可以参考,另外一篇文章https://www.wulaoer.org/?p=2652,好了,没有了,看看其他的吧。
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏