Published on

Editing a File in a Kubernetes Container with No Editor


Today I had to modify a file in a running container to debug why something was breaking.

Normally this is a 2 minute process, this ended up being an ordeal:

  • Exec into the container: kubectl exec -it myContainer -n myNamespace -- bash
  • Locate the file
  • vim myFile
  • No command found for vim
  • Ok not super unusual in lightweight containers
  • Surely there's vi! Even ancient Unix distros have it: vi myFile
  • No command found for vi
  • face-palm
  • Hmm 🤔 emacs
  • No :'(
  • Ok let's see what $editor is configured
  • \usr\bin\nano
  • Ok nano it is
  • Command not found, unknown error
  • ...
  • Doh, this container is foobar!
  • Turns out there is no nano... or any editor for that matter anywhere on this container 🙃
  • Ok no editor... I can't install one as this pod is running in a locked down environment...
  • Fine let's dump the file on the host
  • Edit the file
  • Copy back: kubectl cp myAwesomeFile namespaceOfPod/myPodName:/awesome/file/location
  • Done - phew 🍻