Execute set command via kubectl fails

9/4/2021

I want to execute set in a pod, to analyze the environment variables:

kubectl exec my-pod -- set

But I get this error:

OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "set": executable file not found in $PATH: unknown

I think, this is a special case, because there's no executable set like there's for example an execute ls.

Remarks

  • When I open a shell in the pod, it's possible to call set there.
  • When I call kubectl exec with other commands, for example ls, I get no error.
  • There are some other questions regarding kubectl exec. But these do not apply to my question, because my problem is about executing set.
-- Matthias M
kubectl
kubernetes

1 Answer

9/4/2021

set is not a binary but instead a shell command that sets the environment variable.

If you want to set an environment variable before executing a follow up command consider using env

kubectl exec mypod -- env NAME=value123 script01

# or 

kubectl exec mypod -- /bin/sh -c 'NAME=value123 script01'

see https://stackoverflow.com/a/55894599/93105 for more information

if you want to set the environment variable for the lifetime of the pod then you probably want to set it in the yaml manifest of the pod itself before creating it.

you can also run set if you first run the shell

kubectl exec mypod -- /bin/sh -c 'set'
-- codebreach
Source: StackOverflow