Skip to content

Instantly share code, notes, and snippets.

@nijave
Created May 18, 2026 12:38
Show Gist options
  • Select an option

  • Save nijave/48fb7ba53b49e301d5f57aaa4a461db3 to your computer and use it in GitHub Desktop.

Select an option

Save nijave/48fb7ba53b49e301d5f57aaa4a461db3 to your computer and use it in GitHub Desktop.
"ssh" into a Kubernetes node with a privileged pod and chroot
kssh () {
pod_name=nick-ssh
kubectl delete pod $pod_name
k8s_node=$1
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
name: "${pod_name}"
spec:
restartPolicy: Never
hostNetwork: true
hostPID: true
containers:
- name: ubuntu
image: ubuntu:22.04
command: [sleep]
args: [infinity]
securityContext:
privileged: true
volumeMounts:
- name: host
mountPath: /host
volumes:
- name: host
hostPath:
path: /
type: Directory
nodeName: "${k8s_node}"
EOF
kubectl wait --for=condition=Ready=true "pod/${pod_name}"
kubectl exec -i --tty "${pod_name}" -- chroot /host /bin/bash
kubectl delete pod --wait=false $pod_name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment