how to extend environment variable for a container in Kubernetes

If you only need this path declaration for the command you are running with, you can add it to containers section, under args

Example:

spec:
  containers:
  - name: blah
    image: blah
    args:
    - PATH="$PATH:/usr/local/nvidia/bin" blah

If you do not have args specified in your yaml, you probably have a CMD specified in your Dockerfile that will just run your container with the command automatically. Thus you can add the following to your Dockerfile.

CMD ["PATH=$PATH:/usr/local/nvidia/bin", "blah"]

If you want this to be in your container in general, you would have to add to the .profile or .bashrc file of the user within the container you are using. This will probably involve creating a new image with these new files baked in.

Tags:

Kubernetes