Created
February 20, 2023 07:43
-
-
Save strowi/51f1cb38ba68f5576304e7a34510ca45 to your computer and use it in GitHub Desktop.
kubernetes debug-node pod with selector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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