Skip to content

Instantly share code, notes, and snippets.

@Reelix
Created September 29, 2021 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reelix/0d676e2d8439317341b517c12840aaa3 to your computer and use it in GitHub Desktop.
Save Reelix/0d676e2d8439317341b517c12840aaa3 to your computer and use it in GitHub Desktop.
A yaml file for creating a pod on Kubernetes that mounts the hosts /
apiVersion: v1
kind: Pod
metadata:
name: rootpod
spec:
containers:
- name: rootpod
image: nginx # Pull from an existing pod
imagePullPolicy: IfNotPresent
volumeMounts:
- name: root-of-host
mountPath: /rootpod
volumes:
- name: root-of-host
hostPath:
path: /
@Reelix
Copy link
Author

Reelix commented Aug 29, 2022

1.) List available images

./kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |sort

2.) Replace "nginx" with the full image name

3.) Add the pod

./kubectl apply -f ./rootpod.yaml

4.) Run an interactive bash shell on the pod

./kubectl exec -it rootpod -- bash

5.) Browse to the root of the host

cd /rootpod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment