Kubernetes 数据存储 Secret

Kubernetes base64 About 1,244 words

概念

ConfigMap非常类似,主要用于存储敏感信息,例如密码、秘钥、证书等。

特点

动态更新(定时更新),密文存储(describe不能看到信息,但在Pod容器中会还原成明文)

示例 yml

echo -n 'admin' | base64
echo -n '123456' | base64

输出:

[root@localhost ~]# echo -n 'admin' | base64
YWRtaW4=
[root@localhost ~]# echo -n '123456' | base64
MTIzNDU2

secret.yml

apiVersion: v1
kind: Secret
metadata:
  name: secret
  namespace: dev
type: Opaque
data:
  username: YWRtaW4=
  password: MTIzNDU2

创建pod-secret.yml,挂载到Secret

apiVersion: v1
kind: Pod
metadata:
  name: pod-secret
  namespace: dev
spec:
  containers:
  - name: nginx
    image: nginx:1.17.1
    volumeMounts: # 将 Secret 挂载到目录
    - name: config
      mountPath: /secret/config
  volumes:
  - name: config
    secret:
      secretName: secret

查看 Secret

kubectl describe secret secret -n dev

输出:

[root@localhost ~]# kubectl describe secret secret -n dev
Name:         secret
Namespace:    dev
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
username:  5 bytes
password:  6 bytes

查看 Pod 中内容

进入容器

kubectl exec -it pod-secret -n dev -- /bin/sh

输出:可以看到Pod中的内容是明文的。

[root@localhost ~]# kubectl exec -it pod-secret -n dev -- /bin/sh
# ls /secret/config/
password  username
# more /secret/config/username
admin
# more /secret/config/password
123456
Views: 1,616 · Posted: 2022-03-23

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh