CKA (Certified Kubernetes Administrator)/Kode Kloud

4.Application Lifecycle Management - Env Variables

seulseul 2022. 1. 21. 10:33

APPLICATION LIFECYCLE MANAGEMENT, PRACTICE TEST ENV VARIABLES

Application Lifecycle Management

 
1)  Rolling Updates and Rollbacks
2) Commands and Arguments
6) Init Containers

1. How many PODs exist on the system? in the current(default) namespace

ask : 1

controlplane ~ ➜  kubectl get pod
NAME           READY   STATUS    RESTARTS   AGE
webapp-color   1/1     Running   0          24s

2. What is the environment variable name set on the container in the pod?

ask : APP_COLOR

kubectl describe pod webapp-color

Environment:
      APP_COLOR:  pink

3. What is the value set on the environment variable APP_COLOR on the container in the pod?

ask : pink

 

4. View the web application UI by clicking on the Webapp Color Tab above your terminal.

This is located on the right side.

05. Update the environment variable on the POD to display a green background

Note: Delete and recreate the POD. Only make the necessary changes. Do not modify the name of the Pod.

  • Pod Name: webapp-color
  • Label Name: webapp-color
  • Env: APP_COLOR=green
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: webapp-color
  name: webapp-color
  namespace: default
spec:
  containers:
  - env:
    - name: APP_COLOR
      value: green
    image: kodekloud/webapp-color
    name: webapp-color
controlplane ~ ➜  kubectl get pod webapp-color -o yaml > webapp-test.yaml

controlplane ~ ➜  ls
sample.yaml       webapp-test.yaml

controlplane ~ ➜  vi webapp-test.yaml 

controlplane ~ ➜  kubectl delete pod webapp-color
pod "webapp-color" deleted

controlplane ~ ✖ kubectl apply -f webapp-test.yaml --force
pod/webapp-color created

06. View the changes to the web application UI by clicking on the Webapp Color Tab above your terminal.

If you already have it open, simply refresh the browser.

 
07. How many ConfigMaps exists in the default namespace?
 
ask : 2
Run the command kubectl get configmaps

controlplane ~ ➜  kubectl get configmaps
NAME               DATA   AGE
kube-root-ca.crt   1      26m
db-config          3      2m
 
08. Identify the database host from the config map db-config
 
ask : SQL01.example.com
 
Run the command kubectl describe configmaps and look for DB_HOST option

controlplane ~ ➜  kubectl describe configmaps db-config
Name:         db-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
DB_NAME:
----
SQL01
DB_PORT:
----
3306
DB_HOST:
----
SQL01.example.com

BinaryData
====

Events:  <none>

controlplane ~ ➜
 
 

9. Create a new ConfigMap for the webapp-color POD. Use the spec given below.

  • ConfigName Name: webapp-config-map
  • Data: APP_COLOR=darkblue
kubectl create configmap webapp-config-map --from-literal=APP_COLOR=darkblue

 

Env
: ) 쿠버네티스에서 환경변수를 설정해주는 방식


pod을띄우는것처럼 환경변수 정보가 담긴 "configMaps"을 띄울수가있다.
 


# 기존에 띄워져있는 configmaps 확인

kubectl get configmaps


# configmaps에 어떤 환경변수가 선언되어있는지 확인

kubectl describe configmaps <configmaps-name>


1. configmap yaml 파일 생성

configmap 파일을 만들려면 pod을 만들었던것처럼 yaml파일안에 kind부분을 "ConfigMap"으로 설정해주면된다.



그후 , 만들어준 ConfigMap을 띄우고자하는 Pod에 연결시켜주려면 다음과같이 Pod yaml파일에 명시를 해주면된다.




containers에 envFrom-configMapRef 을써줘서 대응되는 configMap 이름을 넣어주면된다.

10. Update the environment variable on the POD to use the newly created ConfigMap

Note: Delete and recreate the POD. Only make the necessary changes. Do not modify the name of the Pod.

  • Pod Name: webapp-color
  • EnvFrom: webapp-config-map
Set the environment option to envFrom and use configMapRef webapp-config-map.
apiVersion: v1
data:
  APP_COLOR: darkblue
kind: ConfigMap
metadata:
  name: webapp-config-map
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: webapp-color
  name: webapp-color
  namespace: default
spec:
  containers:
  - envFrom:
    - configMapRef:
         name: webapp-config-map
    image: kodekloud/webapp-color
    name: webapp-color

11. View the changes to the web application UI by clicking on the Webapp Color Tab above your terminal.

If you already have it open, simply refresh the browser.


Bookmark

 

https://kubernetes.io/docs/concepts/configuration/configmap/

 

ConfigMaps

A ConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. A ConfigMap allows you to decouple environment-specifi

kubernetes.io