I have a cli that does a few different operations on pod startup and can be run from inside the pod like kubectl -n default -exec my-deployed-pod-xyz -- /path/my_cli -command health
and runs fine like that, it logs success messages and actually does what I want it to.
In that commmand it does os.Exit(0)
if it succeeds and os.Exit(1)
if an error occurs, as per usual (it's written in go but that's just a detail).
Unfortunately when I specify the command (the part to the right of --
in the example above) as an exec in my kubernetes deployment yaml, it appears to always fail. To remedy this I made a cmd_wrapper.sh
that just has:
#! /bin/bash
if /path/my_cli -command health ; then
exit 0
else
exit 1
fi
(maybe I don't need the if else but I thought I'd make sure).
Anyway when I use that as the exec command in k8s it works fine, which made me think the problem is the multiple words in the original command. I tried:
readinessProbe:
exec:
command:
- /path/my_cli -command health
Also:
command:
- /path/my_cli
- -command
- health
And:
command: ["/path/my_cli -command health"]
Also:
command: ["/path/my_cli", "-command", "health"]
Unfortunately none of these seemed to work. I can still use the bash wrapper script but would be nice to know what's going on here...
Edit: thanks to larsks I found the error log in the journal of the worker node, it looks like this:
Dec 18 14:32:33 mcrumzy-worker-1.nasa.gov kubelet[1068]: rpc error: code = Unknown desc = command error: time="2023-12-18T14:32:33-08:00" level=error msg="exec failed: container_linux.go:380: starting container process caused: exec: \"/app/my_cli -command health\": stat /app/my_cli -command health_check: no such file or directory"
So that doesn't help too much, just makes it look like it can't parse the command somehow. Escaping maybe?
This...
...is not a valid configuration. The argument to
command
(just like the argument tocommand
in a container spec) must be a list of arguments. The error you're getting in your logs......occurs because the system is looking for a file in
$PATH
named literally/app/my_cli -command health
. There is no file with that name!One of your attempts looks correct:
(You can see that matches the syntax shown in the documentation.)
Update your Deployment manifest to use the above syntax, and then look and see if there's a new error message.