wipe-node 924 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. if [ $# -ne 1 ]; then
  3. echo "Incorrect number of arguments"
  4. fi
  5. NODE=$1
  6. echo "Resetting ${NODE}"
  7. NODEIP=$(kubectl get nodes -o wide | grep ${NODE} | grep -v "INTERNAL-IP" | awk '{print $6}')
  8. DISKS=$(talosctl -n ${NODEIP} disks | awk '{print $2}' | grep -v DEV | grep -v "/dev/sdg" | grep -v "/dev/mmc")
  9. echo "Disks: $DISKS"
  10. echo "Node IP: $NODEIP"
  11. for d in $DISKS ; do
  12. echo "Creating disk-wipe pod to clear $d on $NODE (${NODEIP})"
  13. cat <<EOF | kubectl apply -f -
  14. apiVersion: v1
  15. kind: Pod
  16. metadata:
  17. name: disk-wipe
  18. spec:
  19. restartPolicy: Never
  20. nodeName: ${NODE}
  21. containers:
  22. - name: disk-wipe
  23. image: busybox
  24. securityContext:
  25. privileged: true
  26. command: ["/bin/sh", "-c", "dd if=/dev/zero bs=1M count=100 oflag=direct of=${d}"]
  27. EOF
  28. kubectl wait --timeout=900s --for=jsonpath='{.status.phase}=Succeeded' pod disk-wipe
  29. kubectl delete pod disk-wipe
  30. done
  31. talosctl -n ${NODEIP} reboot