Kubernetes (十一) 存储——Secret配置管理

一. 简介

从文件创建

echo -n 'admin' > ./username.txt

echo -n 'westos' > ./password.txt

kubectl create secret generic db-user-pass --from-file=./username.txt --from- file=./password.txt

编写yaml文件创建

**1.**创建编辑文件 vim mysecret.yaml

apiVersion: v1

kind: Secret

metadata:

name: mysecret

type: Opaque

data:

username: YWRtaW4= #这两必须是base64编码后的值

password: d2VzdG9z

**2.**将secret挂载到Volume中 vim pod1.yaml

apiVersion: v1
kind: Pod
metadata:
name: mysecret
spec:
containers:

  • name: nginx
    image: nginx
    volumeMounts:
  • name: secrets
    mountPath: "/secret" #创建的目录挂载点
    readOnly: true #只读
    volumes:
  • name: secrets
    secret:
    secretName: mysecret

删除pod: kubectl delete -f pod1.yaml

向指定路径映射secret密钥

1. 创建编辑文件 vim pod2.yaml

apiVersion: v1

kind: Pod

metadata:

name: mysecret

spec:

containers:

  • name: nginx

image: nginx

volumeMounts:

  • name: secrets #定义的挂载名

mountPath: "/secret"

readOnly: true

volumes:

  • name: secrets #卷挂载

secret: #哪个secret名称

secretName: mysecret #这个

items: #因为secret有多组key

  • key: username #指定的这个key

path: my-group/my-username #这里是相对路径需要把base路径(/secret)加上就是绝对路径
删除pod: kubectl delete -f pod2.yaml

存储docker registry的认证信息

1. 在私有仓库创建新项目(不公开)

**2.**创建编辑文件 vim pod3.yaml

apiVersion: v1

kind: Pod

metadata:

name: mypod

spec:

containers:

  • name: game2048

image: reg.westos.org/westos/game2048

#imagePullSecrets: #拉取的密钥

- name: myregistrykey #这里先注释掉

这里看到创建失败

3. 解决方案 创建secret密钥

kubectl create secret docker-registry myregistrykey --docker-server=reg.westos.org --docker-username=admin --docker-password=westos --docker-email=yakexi007@westos.org

4. 因为不是Deploment控制器创建的 得删除刚才的pod

kubectl delete pod --all

5. 修改配置文件 去掉刚才得注释选项即可 vim pod3.yaml

apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:

相关推荐
A小辣椒15 小时前
TShark:Wireshark CLI 功能
linux
A小辣椒19 小时前
TShark:基础知识
linux
AlfredZhao21 小时前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
小猿姐1 天前
MySQL Top 10 热点问题 AI 运维实战:从内核诊断到云原生运维
mysql·云原生·aiops
AlfredZhao1 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334662 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪2 天前
linux 拷贝文件或目录到指定的位置
linux
阿里云云原生2 天前
深入内核:拆解 OpenTelemetry eBPF 探针如何优雅地“透视”多语言微服务?
云原生
大树882 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠2 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql