Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
kubectl should be able to be used to run (apply) config files via shebang #73874
Having to add
Partial support for implementing this is already made as kubectl already accepts stdin input via
#!/usr/bin/env kubectl apply -f - --- # rest of yaml file
I mention that this feature is already supported by other tools, and one notable example
I was even able to make create a proxy bash script
#!/usr/bin/env bash # Add this shebang and make the yaml file executable: #!/usr/bin/env kubex set -euo pipefail [ $# -ge 1 -a -f "$1" ] && input="$1" || input="-" cat $input | kubectl apply -f - $*
When trying to use kubectl itself for this, it seems that the CLI parsing in kubectl is failing to detect that it was called via shebang call and fails with something like:
This is happening because when shebang execution happen the first argument is the script name and not the kubectl command. I implemented detection for this and in the past and doing a pop on args should make it work.
While it is possible to implement this missing feature in another utilitu script, it would be the best to implement this directly in kubectl as it could improve the user experience.
The quoted error clearly states it's working as expected:
that's cobra returning it can't find a command named
Yeah, I'm not comfortable with that either. Somehow text files (yaml being one of them) are not meant for shebangs imho.