본문 바로가기

Container/Kubernetes

[Kubernetes] Application 기능으로 이해하기 - Configmap, Secret

728x90
반응형

> Configmap : pod내 환경변수 설정

- pod가 생성될때 한번만 주입, 때문에 pod를 재시작 해야만 수정된 Configmap 적용됨.

- data(Configmap) <-> envForm(pod)

- data(Configmap) <-> Volume Mounts : mountPath(pod)

 

> Secret : pod내 volume과 연결되어 변수 설정

- Secret을 Volume Mounts로 연결해 놓았기 때문에, 수정시 즉시 반영,

- stringData(Secret) -> data(Secret, base64로 인코딩) <-> Volume Mounts : mountPath(pod)

 

[ Configmap ]

 

[ Secret ]

- Secret을 Base64로 저장하는 이유 : 인증서와 같은 바이너리 파일의 경우 문자열로 저장이 불가능하기 때문에 Base64로 인코딩해서 저장할 수 있도록 함.

 


ㅁ 실습

▶ 입력값 확인

////////////////////////////////// kubectl
// Configmap 확인
kubectl describe -n anotherclass-123 configmaps api-tester-1231-properties
kubectl get -n anotherclass-123 configmaps api-tester-1231-properties -o yaml
kubectl get -n anotherclass-123 configmaps api-tester-1231-properties -o jsonpath='{.data}'

// Secret 확인
kubectl get -n anotherclass-123 secret api-tester-1231-postgresql -o yaml
kubectl get -n anotherclass-123 secret api-tester-1231-postgresql -o jsonpath='{.data}'

// Secret data에서 postgresql-info가 Key인 Value값만 조회 하기
kubectl get -n anotherclass-123 secret api-tester-1231-postgresql -o jsonpath='{.data.postgresql-info\.yaml}'

// Secret data에서 postgresql-info가 Key인 Value값을 Base64 디코딩해서 보기
kubectl get -n anotherclass-123 secret api-tester-1231-postgresql -o jsonpath='{.data.postgresql-info\.yaml}' | base64 -d

 

 

▶ 컨테이너 내부에 확인

/////////////////////////////////// dashboard > 파드 > Exec
// Configmap 환경 변수 확인
env

// Secret 파일 확인
ls /usr/src/myapp/datasource
cat /usr/src/myapp/datasource/postgresql-info.yaml

// java 실행 인자 확인
jps -v

////////////////////////////////// kubectl
/ 사용 포맷
kubectl exec -n <namespace-name> -it <pod-name> -- <command>

kubectl exec -n anotherclass-123 -it api-tester-1231-5c9f87b99c-4bdx6 -- env
kubectl exec -n anotherclass-123 -it api-tester-1231-5c9f87b99c-4bdx6 -- cat /usr/src/myapp/datasource/postgresql-info.yaml
kubectl exec -n anotherclass-123 -it api-tester-1231-5c9f87b99c-4bdx6 -- jps -v

 

 

▶ API 확인

// Application 정보 확인 (version, profile, role, database) 
http://192.168.56.30:31231/info 

// Application Properties 파일 구성 확인
http://192.168.56.30:31231/properties

 

 

▶ Configmap 수정 후 pod 재시작하여 변화 확인

 

> 참고 URL :

https://cafe.naver.com/kubeops/43

 

728x90
반응형