I'm trying to create a script in order to run multiple kubectl exec
commands against multiple pods with multiple containers. The script seems to generate the command just fine but errors out when attempting to run it.
example command that is generated: kubectl -n <namespace> exec <pod_name> -c <container_name> -- openssl version
When I copy the generated command and run it directly it works fine, but if I try to run the command within the script I get an error.
OCI runtime exec failed: exec failed: unable to start container process: exec: "openssl version": executable file not found in $PATH: unknown
command terminated with exit code 126
snippet from .sh file:
for pod in $PODS; do
CONTAINERS=($(kubectl -n $NAMESPACE get pods $pod -o jsonpath='{.spec.containers[*].name}' | tr -s '[[:space:]]' '\n'))
header "{pod: \"$pod\", containers: \"$(echo $CONTAINERS | tr -d '\n')\"}"
if [ "$DRYRUN" != "true" ]; then
for container in $CONTAINERS; do
echo "COMMAND BEING RUN: \"kubectl -n $NAMESPACE exec $pod -c $container -- $COMMAND\""
kubectl -n $NAMESPACE exec $pod -c $container -- $COMMAND
done
fi
done