Interview Prep/Kubernetes/Upgrades, etcd, disaster recovery and incidents

How do you copy files in and out of a pod?

BeginnerScenarioUpgrades, etcd, disaster recovery and incidents
Answer

Situation read → You need to grab a heap dump from a pod.

What I'd do →

  1. kubectl cp app-pod:/tmp/heap.hprof ./heap.hprof -c app -n prod
  2. For large files use kubectl exec ... -- tar cf - /tmp | tar xf -
  3. Check the image has tar since cp relies on it
  4. Clean up the file in the pod afterwards
  5. Prefer shipping dumps to S3 automatically for production

Why → kubectl cp streams a tar archive through the API server.

Interview tip → Say distroless images need an ephemeral debug container instead.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Upgrades, etcd, disaster recovery and incidents