I need some help for environment variables task in kodekloud engineer level 2 task

Hi All,

I need some help in knowing what am doing wrong here , I am sure its a indentation problem but am not sure

My question is

There are a number of parameters that are used by the applications. We need to define these as environment variables, so that we can use them as needed within different configs. Below is a scenario which needs to be configured on Kubernetes cluster. Please find below more details about the same.

  1. Create a pod named envars.
  2. Container name should be fieldref-container, use image busybox preferable latest tag, use command 'sh', '-c' and args should be

'while true; do echo -en '/n'; printenv NODE_NAME POD_NAME; printenv POD_IP POD_SERVICE_ACCOUNT; sleep 10; done;'

(Note: please take care of indentations)

  1. Define Four environment variables as mentioned below:

a.) The first env should be named as NODE_NAME, set valueFrom fieldref and fieldPath should be spec.nodeName.

b.) The second env should be named as POD_NAME, set valueFrom fieldref and fieldPath should be metadata.name.

c.) The third env should be named as POD_IP, set valueFrom fieldref and fieldPath should be status.podIP.

d.) The fourth env should be named as POD_SERVICE_ACCOUNT, set valueFrom fieldref and fieldPath shoulbe be spec.serviceAccountName.

  1. Set restart policy to Never.
  2. To check the output, exec into the pod and use printenv command.

Hi @kaleem.m1rz421

Is this from one of KodeKloud’s labs? If so, can you please share the link to the lab?

It would help if you could also share the Pod manifest in a codeblock using three backticks or formatting button </> in the text window.

PS: You can try with this format once:

...
      command: ["sh", "-c"]
      args:
        - |
          while true; do 
            echo -en '\n'; 
            printenv NODE_NAME POD_NAME; 
            printenv POD_IP POD_SERVICE_ACCOUNT; 
            sleep 10; 
          done;
...

Regards.

This is from Kodekloud engineer level 2

Link: https://engineer.kodekloud.com/task?id=6407205e741b204d59fbea03&status=start

Hi @Santosh_KodeKloud ,

I got the exact same question in the kubernetes docs with a slight change in env variables, I understood now what I did wrong.

We can refer : Expose Pod Information to Containers Through Environment Variables | Kubernetes

Thanks for the help.