
인프런 워밍업 스터디 클럽 4기 데브옵스 - 미션3 (Configmap, Secret)
2개월 전
Application 기능으로 이해하기 - Configmap, Secret > 응용과제 [미션3]
ConfigMap, Secret이란?
Kubernetes에서 ConfigMap은 설정 파일이나 일반 설정값
Secret은 민감한 정보를 안전하게 관리하기 위한 리소스
응용1. ConfigMap의 환경변수들을 Secret으로 전환해라
Step 1. Secret 생성 방법
Dashboard에서 Secret 생성:
apiVersion: v1
kind: Secret
metadata:
namespace: anotherclass-123
name: api-tester-1231-properties
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
stringData:
spring_profiles_active: "dev"
application_role: "ALL"
postgresql_filepath: "/usr/src/myapp/datasource/dev/postgresql-info.yaml"
kubectl로 Secret 생성 (YAML):
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
namespace: anotherclass-123
name: api-tester-1231-properties
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
data:
spring_profiles_active: $(echo -n "dev" | base64 -w0)
application_role: $(echo -n "ALL" | base64 -w0)
postgresql_filepath: $(echo -n "/usr/src/myapp/datasource/dev/postgresql-info.yaml" | base64 -w0)
EOF
kubectl 단축 명령어로 생성:
kubectl create secret -n anotherclass-123 generic api-tester-1231-properties2 \
--from-literal=spring_profiles_active=dev \
--from-literal=application_role=ALL \
--from-literal=postgresql_filepath="/usr/src/myapp/datasource/dev/postgresql-info.yaml"
Step 2. Deployment에 적용
envFrom:
- secretRef:
name: api-tester-1231-properties
kubectl edit -n anotherclass-123 deployments.apps api-tester-1231
응용2. Secret의 DB정보를 ConfigMap으로 전환해보라
Step 1. ConfigMap 생성
apiVersion: v1
kind: ConfigMap
metadata:
namespace: anotherclass-123
name: api-tester-1231-postgresql
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
data:
postgresql-info.yaml: |
driver-class-name: "org.postgresql.Driver"
url: "jdbc:postgresql://postgresql:5431"
username: "postgres"
password: "postgres"
Step 2. Deployment에 VolumeMount 설정
volumeMounts:
- name: configmap-datasource
mountPath: /usr/src/myapp/datasource/dev
volumes:
- name: configmap-datasource
configMap:
name: api-tester-1231-postgresql
kubectl edit -n anotherclass-123 deployments.apps api-tester-1231
미션3 소감
ConfigMap과 Secret은 쿠버네티스 환경에서 설정값을 분리하고 보안을 강화하는 도구임을 확인함
Secret을 환경변수로 직접 연결하거나, ConfigMap을 파일로 마운트하는 방식 모두 실전에서 다양하게 활용될 수 있다는 것을 확인했고, 실제 운영을 위한 구성을 경험해볼 수 있었음
댓글을 작성해보세요.