pod 挂载点 mysql_Pod挂载(Secret )
一種特殊的Volume: Projected Volume ,你可以把它翻譯為“投射數據卷”。
Ps:Projected Volume 是 Kubernetes v1.11 之后的新特性
在 Kubernetes 中,有幾種特殊的 Volume,它們存在的意義不是為了存放容器里的數據,也不是用來進行容器和宿主機之間的數據交換。這些特殊 Volume 的作用,是為容器提供預先定義好的數據。所以,從容器的角度來看,這些 Volume 里的信息就是仿佛是被 Kubernetes“投射”(Project)進入容器當中的。這正是 Projected Volume 的含義。
到目前為止,Kubernetes 支持的 Projected Volume 一共有四種:
1.Secret(存放數據庫的 Credential 信息)
2.ConfigMap(ConfigMap 保存的是不需要加密的,應用所需的配置信息)
3.Downward API(讓 Pod 里的容器能夠直接獲取到這個 Pod API 對象本身的信息)
4.Server Account(定義授權信息,特殊的Secret)
Secret 最典型的使用場景,莫過于存放數據庫的 Credential 信息。
# secret-host.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-test
spec:
containers:
- name: nginx-secret
image: busybox
args:
- sleep
- "86400"
volumeMounts:
- name: rousecret
mountPath: "/projected-volume" #將Volume掛載到容器內部的/projected-volume目錄下
readOnly: true
volumes:
- name: rousecret
secret:
secretName: rousecret
#secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: rousecret
type: Opaque
data:
user: YWRtaW4=
pass: MTIzNDU2
這里的user以及pass均使用base6轉碼:
[root@k8s-master pods]# echo -n "admin" | base64
YWRtaW4=
[root@k8s-master pods]# echo -n "123456" | base64
MTIzNDU2
具體步驟:
kubectl create -f secret.yaml #創建scerets
kubectl create -f secret-host.yaml #創建容器
kubectl exec -it nginx -c nginx-secret sh #進入容器
/ # cat /projected-volume/..data/user
admin
/ # cat /projected-volume/..data/pass
123456
[root@k8s-master pods]# kubectl get secrets
NAME TYPE DATA AGE
rousecret Opaque 2 51m
修改user以及pass值
#方法一
[root@k8s-master pods]# echo "root" | base64
cm9vdAo=
修改secret.yaml中的值
將secret.yaml中user的值替換為上面的值
kubectl apply -f secret.yaml
之后進入容器內即可查看user的值已經改變
方法二
kubectl edit secrets rousecret
同樣的,將上面轉碼得到的值應用到打開的文件中
再進入容器查看時,user以發生改變
當然,也可以把user與pass分開創建
apiVersion: v1
kind: Pod
metadata:
name: test-projected-volume
spec:
containers:
- name: test-secret-volume
image: busybox
args:
- sleep
- "86400"
volumeMounts:
- name: mysql-cred
mountPath: "/projected-volume"
readOnly: true
volumes:
- name: mysql-cred
projected:
sources:
- secret:
name: user
- secret:
name: pass
cat ./username.txt
admin
cat ./password.txt
c1oudc0w!
kubectl create secret generic user --from-file=./username.txt
kubectl create secret generic pass --from-file=./password.txt
[root@k8s-master pods]kubectl get secrets
NAME TYPE DATA AGE
user Opaque 1 51m
pass Opaque 1 51m
總結
以上是生活随笔為你收集整理的pod 挂载点 mysql_Pod挂载(Secret )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python boxplot orien
- 下一篇: lua_path环境变量设置linux,