以爆炸的速度重新创建Kubernetes集群

当创建了Kubernetes集群后,有时可能需要重置和重新创建kubelet和kubeadm。在这种情况下,可以运行以下脚本来重置和重新创建集群。

#!/bin/bash
cd `dirname $0`

rm /home/yamato/kubetoken
KUBENET="10.245.0.0/16"
export KUBECONFIG=/etc/kubernetes/admin.conf
source ~/.bashrc



kubectl delete -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
timeout 30 kubectl delete -f /home/yamato/custom-resources.yaml

kubeadm reset --force
#systemctl stop kubelet
#rm -rf /etc/kubernetes/
#rm -rf ~/.kube/
#rm -rf /var/lib/kubelet/
#rm -rf /var/lib/cni/
#rm -rf /etc/cni/
#rm -rf /var/lib/etcd/
#iptables -F && iptables -X
#systemctl start kubelet


sleep 10

rm -r /etc/cni/net.d
containerd config default | tee /etc/containerd/config.toml
systemctl restart containerd




kubeadm init --cri-socket=/run/containerd/containerd.sock --pod-network-cidr=10.245.0.0/16 | tail -n 2 > /home/yamato/kubetoken
sleep 5
export KUBECONFIG=/etc/kubernetes/admin.conf
source ~/.bashrc
kubectl delete -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
kubectl delete -f /home/yamato/custom-resources.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/tigera-operator.yaml
sleep 10
rm /home/yamato/custom-resources.yaml
wget -P /home/yamato/ https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/custom-resources.yaml
sed -e "s#192.168.0.0/16#$KUBENET#g" -i /home/yamato/custom-resources.yaml
kubectl create -f /home/yamato/custom-resources.yaml
sleep 30

kubectl taint nodes --all node-role.kubernetes.io/control-plane-
kubectl taint nodes --all node-role.kubernetes.io/master-
kubectl taint node --all node.kubernetes.io/not-ready:NoSchedule-

将以下语句以中文本地化的方式释义,只需要一个选项:
导出 KUBECONFIG=/etc/kubernetes/admin.conf
拷贝 ~/.bashrc

观察在calico-system命名空间中的pod:kubectl get pods -n calico-system。

参考文献


https://docs.tigera.io/calico/latest/getting-started/kubernetes/quickstart

这个链接是一个博客文章,可以在 https://blog.turai.work/entry/20220729/1659055307找到。另外一个链接是关于Kubernetes的快速开始指南,可以在https://docs.tigera.io/calico/latest/getting-started/kubernetes/quickstart找到。