[K8S]Eazy way to mirgate weavenet to calico-etcd without reboot

Thanaphat Nuangjumnong
3 min readMay 7, 2021
https://docs.projectcalico.org/reference/architecture/overview

1.Prepare Etcd-cluster for calico
2.Prepare configuration on calico-etcd.yaml (https://docs.projectcalico.org/getting-started/kubernetes/self-managed-onprem/onpremises)
3. Remove all config weave and Network Interface
4.Rollout restart coredns , nodelocal-dns
5.Deploy calico-etcd
6.Rollout restart all pod in the kube-cluster without ns=kube-system.

3. Remove all config weave and Network Interface

#remove weave
kubectl delete -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
#run as root to all servers — clear old virtual interfacerm /etc/cni/net.d/*weave*
ls -l /sys/class/net|grep virtual|grep -v -E “/lo$|/bond0$”|awk {‘print $(NF-2)’}|xargs -I{} ifconfig {} down
ls -l /sys/class/net|grep virtual|grep -v -E “/lo$|/bond0$”|awk {‘print $(NF-2)’}|xargs -I{} ip link delete {}
ls -l /sys/class/net|grep virtual##remove datapath interface
/opt/cni/bin/weave-net delete-datapath datapath
##clear iptables and restart kubelet
iptables -t nat -F && iptables -t mangle -F && iptables -F && iptables -X ; systemctl restart kubelet

4.Rollout restart coredns

#restart coredns pods
kubectl get pod -n kube-system|grep coredns|awk {‘print $1’} | xargs -I{} bash -c ‘kubectl delete pod {} -n kube-system &’

5.Deploy calico-etcd

#deploy calico
kubectl apply -f calico-etcd.yaml
kubectl get pod -n kube-system |greo calico
#restart sample app
kubectl scale — replicas=0 deploy/echo
kubectl scale — replicas=10 deploy/echo

6.Rollout restart all pod in the kube-cluster without ns=kube-system

##how-to-restart-all-pods-in-a-kubernetes-namespace##restart deploy
kubectl get ns -o name|awk -F/ {'print $2'} |grep -vE "^kube-s
ystem$"| xargs -I{} kubectl -n {} rollout restart deploy
##restart daemonset
kubectl get ns -o name|awk -F/ {'print $2'} |grep -vE "^kube-system$"| xargs -I{} kubectl -n {} rollout restart ds
##restart statefulset
kubectl get ns -o name|awk -F/ {'print $2'} |grep -vE "^kube-system$"| xargs -I{} kubectl -n {} rollout restart sts

Wait for along time to restart all pods in the cluster.

I hope you can repeat this step on env.test first than apply on production.

##Rollback Step

#remove calicokubectl delete -f calico-etcd.yaml#run as root to all servers - clear old virtual interfacerm /etc/cni/net.d/10-calico.conflist ; rm /etc/cni/net.d/calico-kubeconfigls -l /sys/class/net|grep virtual|grep -v -E "/lo$|/bond0$"|awk {'print $(NF-2)'}|xargs -I{} ifconfig {} downls -l /sys/class/net|grep virtual|grep -v -E "/lo$|/bond0$"|awk {'print $(NF-2)'}|xargs -I{}  ip link delete {}iptables -t nat -F && iptables -t mangle -F && iptables -F && iptables -X ; systemctl restart kubeletrm /var/lib/weave/weave-netdata.db/opt/cni/bin/weave-net delete-datapath datapath#deploy weavekubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"#restart coredns podskubectl get pod -n kube-system|grep coredns|awk {'print $1'} | xargs -I{} bash -c 'kubectl delete pod {} -n kube-system &'##how-to-restart-all-pods-in-a-kubernetes-namespace##restart deploy
kubectl get ns -o name|awk -F/ {'print $2'} |grep -vE "^kube-s
ystem$"| xargs -I{} kubectl -n {} rollout restart deploy
##restart daemonset
kubectl get ns -o name|awk -F/ {'print $2'} |grep -vE "^kube-system$"| xargs -I{} kubectl -n {} rollout restart ds
##restart statefulset
kubectl get ns -o name|awk -F/ {'print $2'} |grep -vE "^kube-system$"| xargs -I{} kubectl -n {} rollout restart sts

ref. https://docs.projectcalico.org/about/about-calico

--

--