一、配置管理分为两种:
- 加密配置:用来保存密码和token密钥对以及其它敏感的k8s资源。
2.应用配置:我们需要定制化的给应用进行配置,我们需要把定制好的配置文件同步到pod当中的容器。
二、加密配置
1.secret三种类型:1和2分为一类
查看加密的配置

1》service-account-token:k8s集群自建的,用来访问APIserver的secret,pod默认使用这种secret和APIserver进行通信,默认自动挂载到pod/run/secrets/kubenets.io/serviceaccount这个目录下
2》Opaque:用户自定义密码、密钥等等,默认类型就是opaque,语法为generic
3》kubenets.io/dockerconfigjson:配置docker私有仓库的验证信息
4》TLS:用来存储TLS或者SSL证书的私钥
三.Opaque实验
1.创建secret,先创建目录

指定文件创建:

创建secret类型为Opaque(第一种方式),生产中都用命令行指定文件的方式创建很少使用yml文件的方式实现


2.创建secret类型为Opaque(第二种方式):使用yaml文件实现
获取加密的方式


- 如何将secret挂载到pod当中
将secret2里面的加密文件传到pod/etc/secrets目录下



4.将secret作为环境变量传到pod当中:env给容器定义环境变量的语段,也就是给pod当中的容器定义环境变量
定义两个环境变量,名称分别叫user1、password1,user1及password1的值由secret2中的username和password文件给的,所以user=username,password1=password


查看的两种方式


5..kubenets.io/dockerconfigjson:配置docker私有仓库的验证信息实验
首先创建私有仓库加密的secret

指定私有仓库的IP 三台同步vim /lib/systemd/system/docker.service

vim secret.yml
imagePullsecrets:指定docker私有仓库的加密的secret配置
四、configmap:语法和secret一样,但是configmap保存的不是加密信息,主要就是用于保存应用的配置信息;configmap的挂载目录,权限只是只读权限。
1.创建方式:命令行及yml文件两种
命令行方式:指定文件即可

yml文件方式创建:当出现数字时要引号引起来
vim cm.yml

查看当前所有的configmap配置
- 在pod类里面用configmap做pod的环境变量
vim con1-test.yml


3. 通过configmap的方式将nginx.conf内容传到应用容器当中
1》首先创建nginx.conf

2》创建configmap,名称叫nginx-con --from-file指定文件就是/opt/configmap/nginx.conf
3》vim con1.yaml


node1节点查看
进入pod

configmap的热更新

更改端口及路径

再次进入pod查看
进行滚动更新

查看node2节点并且进入html11内往index.html内插入文件666

在主节点访问pod查看插入内容

4》configmap的挂载点目录,权限只是只读模式