새로운 시크릿을 만드세요
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
'DevOps' 카테고리의 다른 글
CKA 예제 리마인더 - 18. OS Upgrades (0) | 2024.11.03 |
---|---|
CKA 예제 리마인더 - 17. Multi Container PODs (1) | 2024.11.02 |
Kubernetes - Secret, ConfigMap (0) | 2024.11.02 |
CKA 예제 리마인더 - 14. Commands and Arguments (0) | 2024.10.31 |
CKA 예제 리마인더 - 13. Rolling Updates and Rollbacks (0) | 2024.10.31 |