Last active
July 16, 2022 00:12
-
-
Save nijave/272bb57d1e4a5fddf162479401712050 to your computer and use it in GitHub Desktop.
Privileged k8s "ssh" pod
This file contains 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
#!/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