DevOps

CKA 예제 리마인더 - 16. Secrets

Vince_rf 2024. 11. 2. 01:48

새로운 시크릿을 만드세요

Secret Name: db-secret

Secret 1: DB_Host=sql01

Secret 2: DB_User=root

Secret 3: DB_Password=password123


kubectl create secret generic db-secret \
> --from-literal=DB_Host=sql01 \
> --from-literal=DB_User=root \
> --from-literal=DB_Password=password123



kubectl get secret db-secret -o yaml 결과값

apiVersion: v1
data:
  DB_Host: c3FsMDE=
  DB_Password: cGFzc3dvcmQxMjM=
  DB_User: cm9vdA==
kind: Secret
metadata:
  creationTimestamp: "2024-11-01T16:32:49Z"
  name: db-secret
  namespace: default
  resourceVersion: "974"
  uid: 2647d353-41b7-4fd0-ba74-f121bdf26610
type: Opaque








파드에 시크릿을 적용하세요

Pod name: webapp-pod

Image name: kodekloud/simple-webapp-mysql

Env From: Secret=db-secret

kubectl run webapp-pod --image=kodekloud/simple-webapp-mysql \
> --dry-run=client -o yaml > ./webapp-pod.yaml



apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: webapp-pod
  name: webapp-pod
spec:
  containers:
  - image: kodekloud/simple-webapp-mysql
    name: webapp-pod
    resources: {}
    envFrom:
    - secretRef:
        name: db-secret
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}



spec.containers.envFrohttp://m.secretRef.name 추가

kubectl replace --force -f webapp-pod.yaml