모든 강의 이미지 출처는 [인프런] 쿠버네티스 어나더 클래스(지상편) - Spring 1,2 입니다.
Quiz) Configmap의 환경변수들을 Secret을 사용해서 작성하고, App에서는 같은 결과가 나오도록 확인해 보세요.
기존 Configmap 정보는 아래와 같습니다.apiVersion: v1 kind: ConfigMap 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: "dev" application_role: "ALL" postgresql_filepath: "/usr/src/myapp/datasource/postgresql-info.yaml"
▶ 기존 Secret과 동일한 설정의 Configmap 생성
apiVersion: v1
kind: Secret
metadata:
namespace: anotherclass-123
name: api-tester-1231-properties
labels:
component: backend-server
instance: api-tester-1231
managed-by: dashboard
name: api-tester
part-of: k8s-anotherclass
version: 1.0.0
stringData:
application_role: GET
postgresql_filepath: /usr/src/myapp/datasource/postgresql-info.yaml
spring_profiles_active: dev
▶ Deployment 내 Pod 설정에 configmapRef 대신 secretRef 로 변경
containers:
- name: api-tester-1231
image: 1pro/api-tester:v1.0.0
ports:
- name: http
containerPort: 8080
protocol: TCP
envFrom:
- secretRef: # configmapRef => secretRef 로 변경
name: api-tester-1231-properties
▶ 결과
# Pod에 설정된 환경변수 목록 조회
[root@k8s-master ~] env
Quiz) 반대로 Secret의 DB정보를 Configmap으로 만들어보고 App을 동작시켜 보세요.
기존 Secret 설정은 다음과 같습니다.apiVersion: v1 kind: Secret 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 stringData: postgresql-info.yaml: | driver-class-name: "org.postgresql.Driver" url: "jdbc:postgresql://postgresql:5431" username: "dev" password: "dev123"
▶ 기존 Configmap과 동일한 설정의 Secret 생성
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: "dev"
password: "dev123"
▶ Deployment 내 Pod volumes 설정에 secret 대신 configmap 로 변경
spec:
volumes:
- name: files
persistentVolumeClaim:
claimName: api-tester-1231-files
- name: configmap-datasource
configMap: # secret => configmap으로 변경
name: api-tester-1231-postgresql
▶ Deployment 내 Pod volumeMounts 설정에 변경된 configmap volume 사용하도록 변경
volumeMounts:
- name: files
mountPath: /usr/src/myapp/files/dev
- name: configmap-datasource # 위에서 변경한 volume명으로 설정
mountPath: /usr/src/myapp/datasource
▶ 결과