Skip to content

Instantly share code, notes, and snippets.

@turkenh
Created July 9, 2018 19:53
Show Gist options
  • Save turkenh/59c644bd110b50382f18db63aa6566bb to your computer and use it in GitHub Desktop.
Save turkenh/59c644bd110b50382f18db63aa6566bb to your computer and use it in GitHub Desktop.
Kubernetes Pod to debug docker of the Node
apiVersion: v1
kind: Pod
metadata:
name: debug-docker
spec:
nodeSelector:
kubernetes.io/hostname: <nodename>
containers:
- name: dind
image: docker:stable
args:
- sleep
- "36000"
securityContext:
privileged: true
volumeMounts:
- name: dockerrun
mountPath: /var/run/docker.sock
terminationGracePeriodSeconds: 30
volumes:
- name: dockerrun
hostPath:
path: /var/run/docker.sock
@turkenh
Copy link
Author

turkenh commented Jul 9, 2018

  1. Replace <nodename> with the one to debug
  2. kubectl create -f debug-docker.yaml
  3. kubectl exec -it debug-docker sh

@turkenh
Copy link
Author

turkenh commented Jul 9, 2018

To access filesystem of a failed pod:

  1. Get the node where the pod run: kubectl get pods -a -o wide
  2. Exec as above
  3. Get docker container id: docker ps -a |grep <some string from pod name>
  4. docker commit <container-id> temp-image
  5. docker run -ti --entrypoint=sh temp-image

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