Print Environment Variables

Ticker

6/recent/ticker-posts

Print Environment Variables

Question The Nautilus DevOps team is working on setting up some pre-requisites for an application that will send greetings to different users. There is a sample deployment that needs to be tested. Below is a scenario which needs to be configured on Kubernetes cluster. Please find below more details about it.

Create a pod named print-envars-greeting.

Configure spec as the container name should be print-env-container and use bash image.

Create three env vars

a. GREETING and its value should be Welcome to

b. COMPANY and its value should be Stratos

c. GROUP and its value should be Group

Use command echo and configure args as ["$(GREETING) $(COMPANY) $(GROUP)"].

You can check the output by using <kubctl logs -f [ pod-name ]> command.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.

Please Note :-  Perform the below commands based on your question  server,  user name & other details might differ . So please read task carefully before executing. All the Best 👍

Solution:  

1. At first  check existing deployment and  pods running status 

thor@jump_host /$ kubectl get pods

No resources found in default namespace.

thor@jump_host /$

2.  Create yaml file with all the parameters , you can copy form GitLab

https://gitlab.com/nb-tech-support/devops/

thor@jump_host /$ vi /tmp/env.yml

thor@jump_host /$ cat /tmp/env.yml

apiVersion: v1

kind: Pod

metadata:

  name: print-envars-greeting

  labels:

    name: print-envars-greeting

spec:

  containers:

    - name: print-env-container

      image: bash

      env:

        - name: GREETING

          value: "Welcome to"

        - name: COMPANY

          value: "Stratos"

        - name: GROUP

          value: "Group"

      command: ["echo"]

      args: ["$(GREETING) $(COMPANY) $(GROUP)"]

thor@jump_host /$

3. Run below command to create pod 

thor@jump_host /$ kubectl create -f /tmp/env.yml

pod/print-envars-greeting created

thor@jump_host /$


4.  Wait for pods to get running status 

thor@jump_host /$ kubectl get pods

NAME                    READY   STATUS      RESTARTS   AGE

print-envars-greeting   0/1     Completed   1          6s

thor@jump_host /$

5.  Validate the task by running below command 

thor@jump_host /$ kubectl logs print-envars-greeting

Welcome to Stratos Group

thor@jump_host /$

 6.  Click on Finish & Confirm to complete the task successful

Happy Learning!!!!

 Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge



Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user