Setting Custom environment variable like PATH, LD_LIBRARY_PATH

Hello Team,
I wanted to set the custom environment variables like PATH, LD_LIBRARY_PATH etc in one of the container. I tried using the configmap with referring the entire PATH variable, but the container keeps crashing. Also I tried to add them as env within the pod configuration file, still the container keeps crashing. Please advise how to customize these values.

I was able to achieve in the below method, please advise if this correct.

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-script
data:
  test.sh: |
   #!/bin/bash
   echo "Hello World"
   export PATH=/somepath:$PATH

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: centosimg
  name: centosimg
spec:
  volumes:
  - name: fileconfig
    configMap:
      name: test-script
      defaultMode: 0777
  containers:
  - image: ubuntu
    name: centosimg
    volumeMounts:
    - name: fileconfig
      mountPath: /script/test.sh
      subPath: test.sh
    command: ["/bin/bash","-c"]
    args: ["source /script/test.sh; env; sleep 400"]

Upon checking the logs, I could see the new path variable.

controlplane ~ ➜  kubectl logs centosimg
Hello World
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_SERVICE_PORT=443
HOSTNAME=centosimg
PWD=/
HOME=/root
KUBERNETES_PORT_443_TCP=tcp://10.43.0.1:443
SHLVL=1
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_ADDR=10.43.0.1
KUBERNETES_SERVICE_HOST=10.43.0.1
KUBERNETES_PORT=tcp://10.43.0.1:443
KUBERNETES_PORT_443_TCP_PORT=443
PATH=/somepath:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env

Hi @nirmalraj17

Apparently you find a solution but you can do more simple without using configMap

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: centosimg
  name: centosimg
spec:
  containers:
  - image: ubuntu
    name: centosimg
    command: ["/bin/sh"]
    args: ["-c", "export PATH=/somepath:$PATH; env; sleep 400"]

and you will have as result :

me@192 ~ % kubectl logs centosimg
KUBERNETES_SERVICE_PORT=443
KUBERNETES_PORT=tcp://10.96.0.1:443
HOSTNAME=centosimg
HOME=/root
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
PATH=/somepath:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_SERVICE_HOST=10.96.0.1
PWD=/

One of the reason why i used this kind of solution is , suppose if we have like 10 or 50 environment variables, everything can be set to a single file and get it sourced in the application while startup.