반응형
[keyword: configmap -> task 를 확인할것], [환경: kodekloud: cluster-upgrade]
: 단순히보면 key 와 value 일지 모르지만 mount 를 통해서 전달하게 되면 nginx.conf 는 file로 전달하고,
DB, user 는 env 라는 환경변수로 전달 하게 되는 것이다.
set configuration context $kubectl config use-context k8s
Expose Configuration settinfs
Task:
- All operations in this question should be performed in the ckad namespace.
- Create a ConfigMap called web-config that contains the following two entries:
• connection_string=localhost:80
• external_url=cncf.io
- Run a pod called web-pod with a single container running the nginx:1.19.8-alpine image, and expose these configuration settings as environment variables inside the container.
1. config 설정
2. namespace 만들기
k get namespace
k create ns ckad
k get ns
3. configmap 생성하기
*Template*
kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
: k 생성, configmap, configmap 이름, --from-literal=[key]=[value] --from-literal=[key]=[value]
k create configmap web-config --from-literal=connection_string=localhost:80 --from-literal=external_url=cncf.io -n ckad
k get configmap -A
https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/
4. 확인
k describe configmaps web-config -n ckad
5. nginx 파드를 만들기
k run web-pod --image=nginx:1.19.8-alpine --port=80 --dry-run=client -o yaml > web-pod.yaml
vi web-pod
: pod 에 namespace: ckad, envForm 넣어주기
6. 확인
k apply -f web-pod.yaml
k get pods -n ckad
kubectl exec -n ckad web-pod -- env
2) 다른방법
: configmap 을 만들지 않고 pod 자체에 넣어주는 방법도 있음.
3) volume Mount 해서 해결하는 문제도 나올 수 있음
차이는 env 로 할 경우 환경변수로 data를 전달하는 방법이고,
volume Mount 의 경우 파일로 전달하는 방법이다.
==> 다음에 한번 더 테스트 해볼것
* voleme mount 하는 방법도 알아두면 좋음
* 본 게시글은 "TTABAE-LEARN" 을 보고 정리한 내용입니다.
728x90
반응형
'cloud > k8s(문제풀이)' 카테고리의 다른 글
[따배쿠CKA]18.ingress 구성 (0) | 2022.08.12 |
---|---|
[따배쿠CKA]17. Secret 운영 (1) | 2022.08.11 |
[따배쿠CKA]15. NodePort 서비스 생성 (0) | 2022.08.11 |
[따배쿠CKA]14. init 컨테이너를 포함한 POD 운영 (0) | 2022.08.11 |
[따배쿠CKA]13. CPU 사용량이 높은 POD 검색 (0) | 2022.08.10 |