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 →
kubectl cp app-pod:/tmp/heap.hprof ./heap.hprof -c app -n prod- For large files use
kubectl exec ... -- tar cf - /tmp | tar xf - - Check the image has
tarsince cp relies on it - Clean up the file in the pod afterwards
- 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.
More on Upgrades, etcd, disaster recovery and incidents
How do you back up etcd on a self-managed cluster?BeginnerHow do you restore a cluster from an etcd snapshot?Advancedetcd database space exceeded: `mvcc: database space exceeded`. What now?AdvancedWalk through a kubeadm minor version upgrade.AdvancedHow do you find deprecated or removed APIs before an upgrade?IntermediateA cluster upgrade broke an operator because its CRD API version was removed. How do you recover?Advanced