文章目录
- 1.master节点
- 2.worker节点
- 3.查看结果
1.master节点
kubeadm reset
清理信息:
cd ~ 进入根目录
ll -a 查看是否存在.kube文件
rm -rf /root/.kube
systemctl restart docker ## 重启docker
systemctl restart kubelet ## 重启kubelet
rm -rf /etc/cni/net.d
初始化主节点:
kubeadm init \
--apiserver-advertise-address=192.168.66.66 \
--control-plane-endpoint=k8s-master \
--image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \
--kubernetes-version v1.20.9 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=172.31.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/
You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:
kubeadm join k8s-master01-31:6443 --token m7xgx0.h8m6si6ws2p0r9n6 \
--discovery-token-ca-cert-hash sha256:f4d3af365aeabab83cf124e5a84aeb8260ae6c0d54a7f5d87928fab37a519aea \
--control-plane
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join k8s-master01-31:6443 --token m7xgx0.h8m6si6ws2p0r9n6 \
--discovery-token-ca-cert-hash sha256:f4d3af365aeabab83cf124e5a84aeb8260ae6c0d54a7f5d87928fab37a519aea
创建配置目录,并复制权限配置文件到用户目录下:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
安装Calico网络插件:
curl https://docs.projectcalico.org/v3.20/manifests/calico.yaml -O
kubectl apply -f calico.yaml
2.worker节点
重制工作节点:
kubeadm reset
删除目录:
rm -rf /root/.kube
rm -rf /etc/cni/net.d
rm -rf /etc/kubernetes/*
加入集群:
kubeadm join k8s-master01-31:6443 --token m7xgx0.h8m6si6ws2p0r9n6 \
--discovery-token-ca-cert-hash sha256:f4d3af365aeabab83cf124e5a84aeb8260ae6c0d54a7f5d87928fab37a519aea
3.查看结果
kubectl get node
kubectl get pod -A