Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does kubectl exec need a --?

Tags:

kubernetes

If I run the command

$ kubectl exec pod-name echo Hello World 

I get a deprecation error message asking me to include the '--' characters.

kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.

Why was the decision made to require the '--' characters there? It seems unnecessary to me. I understand it's deprecated, I'm just trying to understand the reasoning behind the decision.

like image 711
StaticMethod Avatar asked Aug 28 '26 13:08

StaticMethod


1 Answers

According the book "Kubernetes in action" by Marko Luksa:

Why the double dash?

The double dash (--) in the command signals the end of command options for kubectl. Everything after the double dash is the command that should be executed inside the pod . Using the double dash isn’t necessary if the command has no arguments that start with a dash. But in your case, if you don’t use the double dash there, the -s option would be interpreted as an option for kubectl exec and would result in the following strange and highly misleading error: $ kubectl exec kubia-7nog1 curl -s http://10.111.249.153 The connection to the server 10.111.249.153 was refused – did you specify the right host or port? This has nothing to do with your service refusing the connection. It’s because kubectl is not able to connect to an API server at 10.111.249.153 (the -s option is used to tell kubectl to connect to a different API server than the default).

like image 126
Aref Riant Avatar answered Aug 31 '26 06:08

Aref Riant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!