这是什么意思呢?
在 Kubernetes 中,有几种特殊的 Volume,它们存在的意义不是为了存放容器里的数
据,也不是用来进行容器和宿主机之间的数据交换。这些特殊 Volume 的作用,是为容器
提供预先定义好的数据。所以,从容器的角度来看,这些 Volume 里的信息就是仿佛是被
Kubernetes“投射”(Project)进入容器当中的。这正是 Projected Volume 的含义。
到目前为止,Kubernetes 支持的 Projected Volume 一共有四种:
1. Secret;
2. ConfigMap;
3. Downward API;
4. ServiceAccountToken。
在今天这篇文章中,我首先和你分享的是 Secret。它的作用,是帮你把 Pod 想要访问的加
密数据,存放到 Etcd 中。然后,你就可以通过在 Pod 的容器里挂载 Volume 的方式,访
问到这些 Secret 里保存的信息了。
Secret 最典型的使用场景,莫过于存放数据库的 Credential 信息,比如下面这个例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
文档被以下合辑收录
评论