Pod 能夠經過 Volume 或者環境變量的方式使用 Secret,今天先學習 Volume 方式。html
Pod 的配置文件以下所示:學習
① 定義 volume foo
,來源爲 secret mysecret
。編碼
② 將 foo
mount 到容器路徑 /etc/foo
,可指定讀寫權限爲 readOnly
。3d
建立 Pod 並在容器中讀取 Secret:code
能夠看到,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 編碼爲 YWJjZGVm
it
更新 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