What's is the purpose of a trailing '-' in a Kubernetes apply -f -


Solution 1:

The - is a parameter to the -f option, which means to accept input from standard input instead of a named file. Hundreds of UNIX/Linux commands have options like this.

Solution 2:

The - character can be understood as a placeholder for the output of the command which is piped ( using | character ). By using it, we instruct very specifically the subsequent command ( to which the output is piped ), where the standard output of the first command ( it's execution result ) should be placed, in other words how it should be taken or parsed.

So rather than piping the result of:

kubectl create secret generic test --from-file=appsettings.json --dry-run -oyaml

(which happens to be a yaml manifest)

directly to:

kubectl apply -f

which doesn't know what to do with such input (as it expects a file after -f flag), we indicate very precisely where it fits:

kubectl apply -f -

In this case, we instruct kubectl apply command that the piped output from the previous command should be taken instead of a file, which is expected after providing -f flag.