您的位置:首页 > 房产 > 建筑 > k8s的配置管理

k8s的配置管理

2025/2/25 1:59:59 来源:https://blog.csdn.net/Hai990218/article/details/142045624  浏览:    关键词:k8s的配置管理

目录

加密配置

secret的三种类型

创建opaque类型的两种方式

方法一

方法二

如何把secret挂载到pod当中

把secret作为环境变量传到pod当中

指定harbor私有仓库加密的secret配置

应用配置

configmap

创建configmap的方式

在pod里面用configmap做pod的环境变量

**用configmap把配置文件传到应用容器中

**configmap的热更新

**configmap的滚动更新


加密配置

加密配置:就是用来保存密码、token密钥对,以及其他敏感信息的k8s资源

secret的三种类型

1.service-account-token:k8s集群自建的,用来访问apiserver的secret,pod默认使用这种secret和apiserver进行通信。自动挂载到pod的目录 /run/secrets/kubernetes.io/serviceaccount目录

2.opaque:用户自定义的密码、密钥等等,默认类型就是opaque,语法是generic

3.kubernetes.io/dockerconfigjson:配置docker私有仓库的认证信息。

4.TLS:用来存储TLS或者SSL证书和私钥

创建opaque类型的两种方式

方法一

kubectl create secret generic secret1 --from-file=username.txt --from-file=password.txt

方法二

vim secret.yaml

如何把secret挂载到pod当中

把secret作为环境变量传到pod当中

查看变量

指定harbor私有仓库加密的secret配置

kubectl create secret docker-reqistry harbor1 --docker-server=192.168.233.55 --docker-username=admin --docker-password=123456      创建docker-reqistry私有仓库加密的secret

应用配置

应用配置:我们需要定制化的给应用进行配置,我们需要把定制好的配置文件同步到pod当中的容器。

configmap

语法和secret一样,但是configmap保存的不是加密的信息,就是用于应用的配置信息。

创建configmap的方式

方法一:kubectl create configmap conf1 --from-file=/opt/configmap/

方法二:

查看configmap:kubectl get cm

在pod里面用configmap做pod的环境变量

**用configmap把配置文件传到应用容器中

首先准备好一个配置文件

worker_processes  2;
events {worker_connections  1024;
}
http {default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       8081;server_name  localhost;charset utf-8;location / {root   html;index  index.html index.php;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}
}
}

命令行:kubectl create configmap nginx-con --from-file=/opt/configmap/nginx.conf

apiVersion: apps/v1
kind: Deployment
metadata:name: nginx11labels:app: test
spec:replicas: 1selector:matchLabels:app: testtemplate:metadata:labels:app: testspec:containers:- name: nginximage: nginx:1.22ports:- containerPort: 8081volumeMounts:- name: nginx-con1mountPath: /etc/nginx/- name: html-1mountPath: /usr/share/nginx/html/volumes:- name: nginx-con1configMap:name: nginx-con- name: html-1hostPath:path: /opt/html11type: DirectoryOrCreate

**configmap的热更新

先修改configmap

kubectl edit cm nginx-con

kubectl exec -it nginx11-5dc65d85d-hxkmw -- cat /etc/nginx/nginx.conf

此时就更新好了

**configmap的滚动更新

kubectl patch deployment.apps nginx11 --patch '{"spec": {"template": {"metadata": {"annotations": {"version/config": "20240116" }}}}}'

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com