[인프런 워밍업 클럽 4기 - DevOps] 미션 3. ConfigMap, Secret

[인프런 워밍업 클럽 4기 - DevOps] 미션 3. ConfigMap, Secret

응용1 : Configmap의 환경변수들을 Secret을 사용해서 작성하고, App에서는 같은 결과가 나오도록 확인해 보세요.

대시보드 > 신규 리소스 생성

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"

대시보드 > 시크릿 확인

image대시보드 > 디플로이먼트 > 편집으로 아래 구문 수정, 기존 레플리카 셋 제거

# spec > template > spec > containers
envFrom:
  - secretRef:
      name: api-tester-1231-properties

대시보드 > 파드 > 새로 생성된 Pod에서 Exec > 명령어를 통해 환경 변수 확인

env

image

 

응용2 : 반대로 Secret의 DB정보를 Configmap으로 만들어보고 App을 동작시켜 보세요

대시보드 > 신규 리소스 생성

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"

대시보드 > 컨피그 맵 확인

image대시보드 > 디플로이먼트 > 편집으로 아래 구문 수정, 기존 레플리카 셋 제거

# spec > template > spec
volumes:
  - name: configmap-datasource
    configMap:
      name: api-tester-1231-postgresql
# spec > template > spec > containers
volumeMounts:
  - name: configmap-datasource
    mountPath: /usr/src/myapp/datasource/dev

대시보드 > 파드 > 새로 생성된 Pod에서 Exec > 명령어를 통해 파일 확인

cat /usr/src/myapp/datasource/dev/postgresql-info.yaml

image

댓글을 작성해보세요.

채널톡 아이콘