Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm on macOS Catalina 10.15.4, and I'm using minikube v1.11.0 and kubernetes v1.18.3, both installed from brew. Minikube is initialized with the docker engine.

The initialization command is set up like so:

      containers:
        - name: database
          image: "mysql:5.6"
          imagePullPolicy: IfNotPresent
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: 12345
            - name: MYSQL_USER
              value: user
            - name: MYSQL_PASSWORD
              value: password
            - name: MYSQL_DATABASE
              value: db

I'm trying to get a bash script open for one of my running kubectl containers. From research online, it appears that this should be the command that will open a bash window in my terminal:

minikube kubectl exec -it --namespace=tools test-pod -- bash

However, when I run it, I get the following traceback:

Error: unknown shorthand flag: 'i' in -it See 'minikube kubectl --help' for usage.

It doesn't seem to want me using any arguments in my command. Is there something I'm missing, or am I attempting to use a command that is deprecated?

Note: I am able to run exec, but not for opening a bash script. For example, I am able to run the following command:

minikube kubectl exec test-pod -- ls /

And it outputs this following:

kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
bin
boot
dev
docker-entrypoint-initdb.d
entrypoint.sh
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

Edit: I have attempted the following command:

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

And I got the following traceback:

Error: unknown flag: --stdin
See 'minikube kubectl --help' for usage.

It seems like any flags at all, short or long, are failing, and I cannot figure out why they wouldn't be.

like image 295
Ethan Hill Avatar asked Jul 09 '20 20:07

Ethan Hill


1 Answers

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
like image 137
Rico Avatar answered Oct 31 '22 04:10

Rico