0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Kubernetesクラスタを爆速で再作成

Posted at

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-

export KUBECONFIG=/etc/kubernetes/admin.conf
source ~/.bashrc

watch kubectl get pods -n calico-system

参考文献

https://blog.turai.work/entry/20220729/1659055307
https://docs.tigera.io/calico/latest/getting-started/kubernetes/quickstart

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?