Exercise 6.2: Create and consume Secrets
비밀번호로 사용할 문자열을 Base64로 인코딩
echo -n asdf1234 | base64Secret 생성
kubectl create secret generic mysql-credentials --from-literal=password=asdf1234생성된 Secret 확인
kubectl get secrets mysql-credentials -o yamlPod 생성
kubectl run mysql --image=mysqlPod가 생성되었는지 확인
kubectl get pod mysql -wCtrl+C 입력
해당 링크를 통해서 mysql 컨테이너 이미지 리뷰
Pod 삭제
kubectl delete pod mysqlPod 생성
cat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: mysql spec: containers: - name: mysql image: mysql env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql-credentials key: password volumeMounts: - name: mysql mountPath: /opt/mysql volumes: - name: mysql secret: secretName: mysql-credentials EOFPod가 생성 되었는지 확인
kubectl get pod mysqlMYSQL_ROOT_PASSWORD 환경변수가 설정 되었는지 확인
kubectl exec -it mysql -- /bin/bash -c 'echo $MYSQL_ROOT_PASSWORD'/opt/mysql 디렉토리에 파일이 생성됐는지 확인
kubectl exec -it mysql -- ls /opt/mysql/opt/mysql 디렉토리에 생성된 파일 내용 확인
kubectl exec -it mysql -- cat /opt/mysql/password리소스 삭제
{ kubectl delete pod mysql kubectl delete secret mysql-credentials }
PreviousExercise 6.1: Set SecurityContext for a Pod and ContainerNextExercise 6.3: Working with ServiceAccounts
Last updated