Skip to content

Instantly share code, notes, and snippets.

@strowi
Created February 20, 2023 07:43
Show Gist options
  • Save strowi/51f1cb38ba68f5576304e7a34510ca45 to your computer and use it in GitHub Desktop.
Save strowi/51f1cb38ba68f5576304e7a34510ca45 to your computer and use it in GitHub Desktop.
kubernetes debug-node pod with selector
#!/bin/sh -xe
NODE=$(kubectl get nodes -o name |grep $1 | awk -F \/ '{print $2}')
cat << EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: kube-support-$NODE
namespace: kube-system
labels:
app: debug-$NODE
spec:
terminationGracePeriodSeconds: 1
containers:
- name: debian
image: debian:buster
command:
- /usr/bin/nsenter
args:
- --mount=/host/proc/1/ns/mnt
- /bin/bash
securityContext:
allowPrivilegeEscalation: true
capabilities:
add:
- ALL
privileged: true
stdin: true
stdinOnce: true
volumeMounts:
- name: host
mountPath: /host
restartPolicy: Never
hostIPC: true
hostNetwork: true
hostPID: true
volumes:
- name: host
hostPath:
path: /
type: Directory
nodeSelector:
kubernetes.io/hostname: $NODE
tolerations:
- operator: "Exists"
EOF
POD=$(kubectl -n kube-system get po -l app=debug-$NODE --no-headers -o custom-columns=":metadata.name")
kubectl -n kube-system wait --for condition=ready pod $POD
kubectl exec -ti -n kube-system $POD -- bash
kubectl delete -n kube-system pod $POD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment