创建Secret
有四种:
1. 通过 --from-literal:
kubectl create secret generic mysecret1 --from-literal=username=admin --from-literal=password=123456
2.通过--from-literal 对应一个信息条目:
echo -n admin > username
echo -n 123456 > password
kubectl create secret generic mysecret2 --from-file=username --from-file=password
3.通过 --from-enc-file 通过文件xx.txt每行key=Value对应一个信息条目:
cat << eof > a.txt
username=admin
password=123456
eof
kubectl create secret generic mysecret3 --from-env-file=a.txt
4.通过yaml配置文件
echo -n admin | base64
echo -n 123456 | base64
kubectl create secret generic mysecret4 --from-literal=username=admin --from-literal=password=123456 --dry-run=client -o yaml > mysecret4.yaml
kubectl apply -f mysecret4.yaml
查看Sercret
kubectl get secrets mysecret
查看详细信息:
kubectl describe secrets mysecret
kubectl edit secret mysecret
value反编码:
echo -n xxxx | base64 --decode
Volume方法使用Secret
pod通过Volume或者环境变量的方式使用Secret
kubectl run mypod --image=busybox --dry-run=client -o yaml > mypod.yaml
vi mypod.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
run: mypod
name: mypod
spec:
containers:
- image: busybox
name: mypod
args:
- /bin/sh
- -c
- sleep 333333
volumeMounts:
- mountPath: /etc/foo
name: foo
readOnly: true
volumes:
- name: foo
secret:
secretName: mysecret4
执行:
kubectl apply -f mypod.yaml
<