However, if you run that, the hiya pod will fail to start. Somewhere in the kubectl describe output, you should see an error like this:
starting container process caused "exec: \"/usr/local/bin/hello\": permission denied": unknown
By default, ConfigMaps mount in as non-executable. That makes sense, given that they are normally used for things like configuration files, data files, etc. What we’re doing is a bit unusual, but we have some options.
The first option is to change the command on the hiya container from this:
command:
- /usr/local/bin/hello
to this:
command:
- /bin/sh
- /usr/local/bin/hello
That passes the script to /bin/sh as an argument, skipping the part where Linux tries to figure out how to run the script via the #!/... shebang at the top.
Note: this also means that whatever you do put in the shebang is ignored. This script will always run under the Bourne shell, /bin/sh. The shebang is now a comment.
Another way to fix this, that lets us avoid committing to an executor in the command: section is to mount the ConfigMap in with a different defaultMode.
volumes:
- name: bins
configMap:
name: bins
defaultMode: 0755