Home > Net >  kubectl apply fails as if providing mutually exclusive options
kubectl apply fails as if providing mutually exclusive options

Time:04-09

I'm trying to update a k8s deployment using a kubectl apply command. The deployment already exists in the cluster, and was created with the same YAML file provided now to the apply command, but with slight changes.

$ kubectl apply –f ./my_app_deployment_update.yaml
error: must specify one of -f and -k

This problem also arose when creating the object the first time, but I workaround it at that point by using kubectl create.

Of course, the file is available in the current folder. Also I've checked I've no alias defined as kubectl, so the actual command I'm running is just the kubectl you're seeing above.

Finally, my kubectl version is:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.4", GitCommit:"e6c093d87ea4cbb530a7b2ae91e54c0842d8308a", GitTreeState:"clean", BuildDate:"2022-02-16T12:30:48Z", GoVersion:"go1.17.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.12", GitCommit:"e2a822d9f3c2fdb5c9bfbe64313cf9f657f0a725", GitTreeState:"clean", BuildDate:"2020-05-06T05:09:48Z", GoVersion:"go1.12.17", Compiler:"gc", Platform:"linux/amd64"}
WARNING: version difference between client (1.23) and server (1.15) exceeds the supported minor version skew of  /-1

I'm aware of the warning above, but I can't either reduce my kubectl current version (because I work with 1 clusters) nor currently update the k8s version in the cluster. Besides IMO a client/server version mismatch shouldn't be the reason for the error above, regarding arguments provided to the client itself.

Finally, I've been checking the docs but I don't find anything useful for troubleshooting, nor even for the -k option itself.

Any idea about what is happening or how to solve it? Maybe I misunderstood something at a higher level about the usage of kubectl apply?

Update 1

I've checked this other post with the same error, but I've no indentation error. Linter doesn't complain, online validator also says it's OK, and create command didn't complain about anything so the file's indentation was OK all the time.

It doesn't seem a very user-friendly error, and can be triggered by other sorts of problem, so we are playing guessing here...

CodePudding user response:

The problem was it was receiving no argument, instead of both of them.

It seems I copied the command from a powerpoint file, where I was writing it directly before testing. The original character was replaced for another one which looked similar:

–f vs -f

First: 8211, Hex 2013, Oct 20023, Digr -N
Second: 45,  Hex 2d,  Octal 055

So this incorrect character broke the parsing and for kubectl the argument was not being provided. Just replacing it for the regular - from the second sample above made the command work properly.

  • Related