1 概述
作用:加密数据存在etcd里面,让Pod容器以挂载Volume方式进行访问
场景:凭证
2 创建secret加密数据
2.1 创建yaml文件
apiVersion: v1kind: Secretmetadata:name: mysecrettype: Opaquedata:username: test(需base64加密 echo test | base64)password: test(需base64加密)
2.2 执行
// 1 部署kubectl apply secret.yaml// 2 查询kubectl get secret
3 以变量形式挂载到pod容器中
3.1 创建yaml文件
apiVersion: v1kind: Podmetadata:name: mypodspec:containers:- name: nginximage: nginxenv:- name: SECRET_USERNAMEvalueFrom:secretKeyRef:name: mysecretkey: username- name: SECRET_PASSWORDvalueFrom:secretKeyRef:name: mysecretkey: password
3.2 执行
// 1 部署kubectl apply secretpod.yaml// 2 进入容器kubectl exec -it podname bash// 3 查看变量名echo $SECRET_USERNAMEecho $SECRET_PASSWORD
4 以volume形式挂载到pod容器中
4.1 创建yaml文件
apiVersion: v1kind: Podmetadata:name: mypodspec:containers:- name: nginximage: nginxvolumeMounts:- name: foomountPath: "/etc/foo"readOnly: truevolumes:- name: foosecret:secretName: mysecret
4.2 执行
// 1 部署kubectl apply secretvolume.yaml// 2 进入容器kubectl exec -it podname bash// 3 查看变量名cd /etc/foocat passwordcat username
