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:

相关推荐
木头左4 小时前
【Nginx】内网服务源 IP 白名单实战:动态域名解析放行网段 + 端口接管零改造
运维·nginx·白名单·反向代理
Linux-lucky5 小时前
45-Linux学习之旅之防火墙与WEB加固
linux·前端·网络·学习·ubuntu
禁默5 小时前
启元 Q1 二次开发实践:Ubuntu 部署与仿真验证,从 PrimeConsole 到 ROS 2 Humble + RViz
linux·运维·ubuntu
skywalk81636 小时前
把 去也网站 从 Ubuntu 搬到 FreeBSD:一次 Service Jail + nginx 的部署实录
linux·运维·nginx·ubuntu·freebsd
翔云1234567 小时前
RocksDB中,客户端每写入一次数据,需要访问几次磁盘
运维·数据库·mysql
爱莉希雅&&&8 小时前
GitLab 完整学习笔记
linux·运维·服务器
风笙9788 小时前
[文件系统]文件系统挂载与卸载详解
linux
GeW8 小时前
新质生产力路线图解读:数据库性能优化与Linux调优专场
linux·数据库
java_logo8 小时前
Docker 部署 EmulatorJS:轻松搭建浏览器复古游戏平台
游戏·docker·容器·复古游戏·轩辕镜像·emulatorjs·红白机
小杨爱科普9 小时前
制造业上自动化改造,改造部分的专利到底归谁
运维·经验分享·自动化