Search code examples
dockerkubectlgoogle-container-optimized-os

why “kubectl exec -it” cannot login on google container optimised os


When i ran kubectl exec -it /bin/bash, i got error like this

OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"env\": executable file not found in $PATH": unknown command terminated with exit code 126

i made several retries using kubectl and docker exec as but nothing works on google container optimized os

i used the following ones

  • kubectl exec -it <podname> /bin/bash
  • kubectl exec -it <podname> /bin/sh
  • kubectl exec -it <podname> //bin//sh
  • kubectl exec -it <podname> //bin//bash
  • kubectl exec -it <podname> /bash kubectl exec -it <podname> bash

i logged into server and tried to login to docker container using docker exec -it <containerId> <all options mentioned above>. But nothing seems to worked out well.


Solution

  • As BMitch mentioned, your docker image must have bash or sh otherwise your command will fail with the exact same message.

    I just ran a test, created a GKE cluster with Container-Optimized OS with Containerd (cos_containerd) and run the following:

    kubectl run busybox --image busybox:1.28 --command sleep 1200
    kubectl exec busybox -it -- sh
    

    and successfully exec into the pod. This is not related to the OS container optimized, rather it might be related to your docker image.