fix: add Delete arp by kube-vip when uninstall/kubernetes (#2596)

Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
liujian 2025-05-28 14:31:14 +08:00 committed by GitHub
parent ff50e145ca
commit 71265adea8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 71 additions and 62 deletions

View File

@ -33,7 +33,7 @@
{{- end }}
- name: Delete arp by kube-vip
when: eq .kubernetes.control_plane_endpoint.type "vip"
when: eq .kubernetes.control_plane_endpoint.type "kube_vip"
command: |
ip neigh show | grep {{ .kubernetes.control_plane_endpoint.kube_vip.address }} | awk '{print $1 " dev " $3}' | xargs -r -L1 ip neigh delete

View File

@ -0,0 +1,19 @@
---
- name: Delete Node
ignore_errors: true
command: |
kubeadm reset -f
- name: Stop kubelet service
command: |
rm -rf /etc/systemd/system/kubelet.service
rm -rf /etc/systemd/system/kubelet.service.d
systemctl daemon-reload
- name: Delete residue files
command: |
rm -rf /usr/local/bin/kubeadm && rm -rf /usr/local/bin/kubelet && rm -rf /usr/local/bin/kubectl
rm -rf /var/lib/kubelet/
rm -rf /etc/kubernetes/
rm -rf .kube/config
rm -rf /var/lib/etcd

View File

@ -1,53 +1,4 @@
---
- name: Reset kubeadm
ignore_errors: true
command: |
kubeadm reset -f
- include_tasks: kubernetes.yaml
- name: Stop kubelet service
command: |
rm -rf /etc/systemd/system/kubelet.service
rm -rf /etc/systemd/system/kubelet.service.d
systemctl daemon-reload
- name: Delete residue files
command: |
rm -rf /usr/local/bin/kubeadm && rm -rf /usr/local/bin/kubelet && rm -rf /usr/local/bin/kubectl
rm -rf /var/lib/kubelet/
# If /var/log/pods/ is not cleaned up, static pods may accumulate unexpected restarts due to lingering log files interfering with their lifecycle.
rm -rf /var/log/pods/
rm -rf /etc/kubernetes/
rm -rf .kube/config
- name: Reset iptables
command: |
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
ipvsadm -C
ip link del kube-ipvs0
ip link del nodelocaldns
ip link del cni0
{{- if .kubernetes.kube_network_plugin | eq "flannel" }}
ip link del flannel.1
ip link del flannel-v6.1
ip link del flannel-wg
ip link del flannel-wg-v6
{{- end }}
{{- if .kubernetes.kube_network_plugin | eq "cilium" }}
ip link del cilium_host
ip link del cilium_vxlan
{{- end }}
{{- if .kubernetes.kube_network_plugin | eq "calico" }}
ip -br link show | grep cali[a-f0-9]* | awk -F @ '{print $1}' | xargs -r -t -n 1 ip link del
{{- end }}
ip netns show 2>/dev/null | grep cni- | awk '{print $1}' | xargs -r -t -n 1 ip netns del
- name: Delete net.d
command: |
rm -rf /etc/cni/net.d/
rm -rf /var/lib/cni/
{{- if .kubernetes.kube_network_plugin | eq "calico" }}
rm -rf /usr/local/bin/calicoctl
{{- end }}
- include_tasks: network.yaml

View File

@ -0,0 +1,39 @@
---
- name: Reset iptables
command: |
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
ipvsadm -C
ip link del kube-ipvs0
ip link del nodelocaldns
ip link del cni0
{{- if .cni.type | eq "flannel" }}
ip link del flannel.1
ip link del flannel-v6.1
ip link del flannel-wg
ip link del flannel-wg-v6
{{- end }}
{{- if .cni.type | eq "cilium" }}
ip link del cilium_host
ip link del cilium_vxlan
{{- end }}
{{- if .cni.type | eq "calico" }}
ip -br link show | grep cali[a-f0-9]* | awk -F @ '{print $1}' | xargs -r -t -n 1 ip link del
{{- end }}
ip netns show 2>/dev/null | grep cni- | awk '{print $1}' | xargs -r -t -n 1 ip netns del
- name: Delete net.d
command: |
rm -rf /etc/cni/net.d/
rm -rf /var/lib/cni/
{{- if .cni.type | eq "calico" }}
rm -rf /usr/local/bin/calicoctl
{{- end }}
- name: Delete arp by kube-vip
when: eq .kubernetes.control_plane_endpoint.type "kube_vip"
command: |
ip neigh show | grep {{ .kubernetes.control_plane_endpoint.kube_vip.address }} | awk '{print $1 " dev " $3}' | xargs -r -L1 ip neigh delete

View File

@ -69,16 +69,16 @@ func (e playbookExecutor) Exec(ctx context.Context) (retErr error) {
defer e.syncStatus(ctx, retErr)
fmt.Fprint(e.logOutput, `
_ __ _ _ __
| | / / | | | | / /
| |/ / _ _| |__ ___| |/ / ___ _ _
| \| | | | '_ \ / _ \ \ / _ \ | | |
| |\ \ |_| | |_) | __/ |\ \ __/ |_| |
\_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |
__/ |
|___/
`)
_ __ _ _ __
| | / / | | | | / /
| |/ / _ _| |__ ___| |/ / ___ _ _
| \| | | | '_ \ / _ \ \ / _ \ | | |
| |\ \ |_| | |_) | __/ |\ \ __/ |_| |
\_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |
__/ |
|___/
`)
fmt.Fprintf(e.logOutput, "%s [Playbook %s] start\n", time.Now().Format(time.TimeOnly+" MST"), ctrlclient.ObjectKeyFromObject(e.playbook))
klog.V(5).InfoS("deal project", "playbook", ctrlclient.ObjectKeyFromObject(e.playbook))
pj, err := project.New(ctx, *e.playbook, true)