Skip to content

Instantly share code, notes, and snippets.

@nijave
Last active July 16, 2022 00:12
Show Gist options
  • Save nijave/272bb57d1e4a5fddf162479401712050 to your computer and use it in GitHub Desktop.
Save nijave/272bb57d1e4a5fddf162479401712050 to your computer and use it in GitHub Desktop.
Privileged k8s "ssh" pod
#!/usr/bin/env bash
pod_name=nick-ssh
# the first node
k8s_node=$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment