k8s配置资源管理
secret
Configmap*:1.2加入的新特征
secret:保存密码,token,保存敏感的k8s资源
这类数据可以存放在镜像当中,但是防止secret当中可以更方便的控制,减少暴露的风险
保存加密的信息
kubectl create secret
docker-registry:存储docker仓库认证信息以及docker组件认证信息(私有)
generic:是secret的默认模式,Opaque,base64加密编码的secret用户自定义的密码,密钥等等
tls:TLS/SSL,用于存储证书和私钥,https
pod如何来引用secret:
3种方式:
1、挂载的方式,secret挂载到pod当中的一个或者多个容器上的卷里面
2、把secret作为容器的环境变量
3、docker-registry可以作为集群拉取镜像时使用,使用secret可以实现免密登录
指定文件提取类型


--fro,-file=/opt/username.txt:从指定获取加密的信息


#Data
====
password: 13 bytes
username: 13 bytes
data保存的是加密的内容,容器内部可以解密,可以直接引用
创建方式:
陈述式:
#base64就是加密的格式



声明式:



挂载方式:

把加密的文件传到容器内部并解密

环境变量:

使用secret配置免密交互拉取habor私有仓库镜像
我们在搭建好docker的私有仓库后,在使用私有仓库时需要通过docker login指令来登录到私有仓库中。但同时在使用的过程中也会把habor仓库的用户名和密码暴露在命令行中,存在一定的安全隐患。k8s中的secret配置的运用能够实现并且规避这一问题的存在




secret的三种方式:
陈述式创建
声明式创建
引用方式:
挂载使用
设定环境变量
docker-registry
ConfigMap资源配置:
保存的是不需要加密的信息。configmap是1.2引入的功能,应用程序会从配置文件,命令参数,以及环境变量中读取配置信息
configmap在创建容器中,给他注入我们需要的配置信息,既可以是单个的属性,也可以是整个容器的配置文件
1、陈述式
从指定文件创建,可以是一个,也可以是多个文件:(file通过文件上传变成键值对)




使用字面值创建:(literal通过命令行创建上传到键值对)

2、声明式


comfigmap是键值对形式

数据卷使用configmap
准备一个nginx.conf配置文件


写yaml文件


1、我们通过数据卷的形式,把配置文件传给了pod内部容器
2、config的热更新,在pod运行的情况下,对config的配置信息进行修改。直接生效(反应到容器当中)


3、configmap的热更新不会触发pod的滚动更新机制(deployment)
version/config来触发滚动更新
secret:主要作用是保存加密文件,主要的使用方式就是挂载方式
configMap:把配置信息传给容器,主要方式也是挂载
configMap的热更新:热更新可以直接反应到容器的内部,也不会触发pod的更新机制。如果不是需要重启的配置,都可以直接生效
version/config来触发滚动更新(直接删除容器重新拉取也可以)
kubectl patch deployments.apps nginx1 --patch '{"spec": {"template": {"metadata": {"annotations": {"version/conf ig ": "20240116"}}}}}'
需要重启的,可以重启pod
更新:就是把配置信息重新传到容器内,重启也是一样
configMap:就是把配置信息传给容器,键值对形式保存的,非加密的信息