kubectl exec works on single commands, but I cannot enter a bash shell kubectl exec works on single commands, but I cannot enter a bash shell kubernetes kubernetes

kubectl exec works on single commands, but I cannot enter a bash shell


minikube kubectl needs the -- after the command when you want to use it with arguments:

$ minikube kubectl -- exec --stdin --tty --namespace=tools test-pod -- sh

You can also use plain kubectl

If would just make sure that your ~/.kube/config is pointing to the right minikube context/cluster. Typically, any minikube command you run from the shell will cause it to change the context to your minikube cluster. i.e minikube ssh

Then just use kubectl

$ kubectl exec --stdin --tty --namespace=tools test-pod -- sh


I'm unfamiliar with minikube but you should be able to query the command's syntax with:

minikube kubectl exec --help

It's possible that the short flags have been replaced with the long flags:

minikube kubectl exec --stdin --tty ...

It's also possible that the container doesn't include bash but another shell:

minikube kubectl exec --stdin --tty --namespace=tools test-pod -- shminikube kubectl exec --stdin --tty --namespace=tools test-pod -- ash


So, I figured out the solution:

With my configuration, initializing minikube with minikube start --driver=docker does not successfully initialize everything. I changed my driver to virtualbox, and minikube was able to ssh and continue without any issues.

Setup with a docker driver appears to be commonly issue-prone, as this GitHub thread shows: https://github.com/kubernetes/minikube/issues/7332