본문 바로가기

인프런 복습 - 쿠버네티스 어나더 클래스

[Sprint1] Configmap, Secret 과제

 

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

내 생각
Secret은 Pod에 volumeMount 되어있는 상태.
Configmap 자체를 Secret 안에 입력한다. => namespace등 app 내에서 같은 결과라고 볼 수 없음
즉 Configmap을 Secret으로 바꾼다

 

kubernetes 공식문

 

https://kubernetes.io/ko/docs/concepts/configuration/secret/#%EC%8B%9C%ED%81%AC%EB%A6%BF%EC%9D%84-%ED%99%98%EA%B2%BD-%EB%B3%80%EC%88%98-%ED%98%95%ED%83%9C%EB%A1%9C-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

 

시크릿(Secret)

시크릿은 암호, 토큰 또는 키와 같은 소량의 중요한 데이터를 포함하는 오브젝트이다. 이를 사용하지 않으면 중요한 정보가 파드 명세나 컨테이너 이미지에 포함될 수 있다. 시크릿을 사용한다

kubernetes.io

 

 

 

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/postgresql-info.yaml"
---
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"

 

 

  envFrom:
    - secretRef:
        name: api-tester-1231-properties
  volumeMounts:
    - name: db-secret
      mountPath: /usr/src/myapp/datasource

volumes:
- name: db-secret
  secret:
    secretName: api-tester-1231-postgresql

key:value 형식의 데이터만 secretRef에 넣고, 기존의 Secret(postgresql)은 파일 형식이므로 그대로 volume에 넣는다! 

 

 

 

 

 

 

 

 

 

답(일부만!)

 

stringData는 base64로 자동으로 인코딩해준다! 

 

 

 

 

▶ 응용2 : 반대로 Secret의 DB정보를 Configmap으로 만들어보고 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"
  
  driver-class-name: "org.postgresql.Driver"
  url: "jdbc:postgresql://postgresql:5431"
  username: "dev"
  password: "dev123"

 

 

 

난 하나로 합치려고 했는데, 그럴  필요 없이  그냥 그대로 configmap으로 수정하면 된다!