當(dāng)需要存儲(chǔ)敏感數(shù)據(jù)時(shí)可以使用,secret會(huì)以密文的方式存儲(chǔ)數(shù)據(jù)。
創(chuàng)建secret的四種方法
(1)通過--from-literal
#每個(gè)--from-literal對(duì)應(yīng)一個(gè)信息條目
kubectl create secret generic mysecret --from-literal=username=admin --from-literal=password=123456
(2) 通過--from-file
#每個(gè)文件內(nèi)容對(duì)應(yīng)一個(gè)信息條目。
[root@k8s-master ~]# echo -n admin > ./username
[root@k8s-master ~]# echo -n 123456 > ./password
[root@k8s-master ~]# kubectl create secret generic mysecret1 --from-file=./username --from-file=./password
secret/mysecret1 created
[root@k8s-master ~]#
(3)通過--from-env-file
#文件env.txt中每行Key=Value對(duì)應(yīng)一個(gè)信息條目
[root@k8s-master ~]# cat <<EOF > env.txt
> username=admin
> password=123456
> EOF
[root@k8s-master ~]# kubectl create secret generic mysecret2 --from-env-file=env.txt
secret/mysecret2 created
[root@k8s-master ~]#
(4)通過YAML配置文件
文件中的敏感數(shù)據(jù)必須是通過base64編碼后的結(jié)果
通過kubectl describe secret查看條目的Key
使用 kubectl edit secret mysecret查看value
過base64將Value反編碼
當(dāng)pod掛載secret后, Value則以明文存放在容器掛載的路徑文件中
默認(rèn)情況下會(huì)以 數(shù)據(jù)條目的Key作為文件名
自定義存放數(shù)據(jù)的文件名
配置pod使用環(huán)境變量方式使用secret
文章來源:http://www.zghlxwxcb.cn/news/detail-694470.html
缺點(diǎn):環(huán)境變量方式無法支持secret動(dòng)態(tài)更新文章來源地址http://www.zghlxwxcb.cn/news/detail-694470.html
到了這里,關(guān)于在k8s中使用secret存儲(chǔ)敏感數(shù)據(jù)與四種用法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!