volume 方式使用 Secret - 天天5分钟玩转 Docker 容器技术(157)

Pod 能够经过 Volume 或者环境变量的方式使用 Secret,今天先学习 Volume 方式。html

Pod 的配置文件以下所示:学习

① 定义 volume foo,来源为 secret mysecret编码

② 将 foo mount 到容器路径 /etc/foo,可指定读写权限为 readOnly3d

建立 Pod 并在容器中读取 Secret:code

767.png

能够看到,Kubernetes 会在指定的路径 /etc/foo 下为每条敏感数据建立一个文件,文件名就是数据条目的 Key,这里是 /etc/foo/username 和 /etc/foo/password,Value 则以明文存放在文件中。htm

咱们也能够自定义存放数据的文件名,好比将配置文件改成:blog

这时数据将分别存放在 /etc/foo/my-group/my-username 和 /etc/foo/my-group/my-password 中。get

以 Volume 方式使用的 Secret 支持动态更新:Secret 更新后,容器中的数据也会更新。同步

将 password 更新为 abcdef,base64 编码为 YWJjZGVmit

更新 Secret。

几秒钟或,新的 password 会同步到容器。

以上是经过 Volume 使用 Secret,下节咱们会学习经过环境变量使用 Secret。

书籍:

1.《天天5分钟玩转Kubernetes》
https://item.jd.com/26225745440.html

2.《天天5分钟玩转Docker容器技术》
https://item.jd.com/16936307278.html

3.《天天5分钟玩转OpenStack》
https://item.jd.com/12086376.html

相关文章
相关标签/搜索