当前位置:网站首页>kubernetes资源对象介绍及常用命令(五)-(ConfigMap)
kubernetes资源对象介绍及常用命令(五)-(ConfigMap)
2022-07-03 05:31:00 【江小南】
一、ConfitMap
配置集,抽取应用配置。
ConfigMap保存在kubernetes的etcd中。
ConfigMap可以将文件直接挂载到Pod内,区别于上篇文章中的PV&PVC挂载目录。
创建ConfigMap
命令行方式
[[email protected] ~]# vi redis.conf
[[email protected] ~]# cat redis.conf
appendonly yes
[[email protected] ~]# kubectl create cm redis-conf --from-file=redis.conf
configmap/redis.conf created
[[email protected] ~]#
首先有redis.conf文件,然后将文件做成ConfigMap。
yaml方式,redis-conf.yml
apiVersion: v1
data:
redis.conf: |
appendonly yes
kind: ConfigMap
metadata:
name: redis-conf
namespace: default
data是所有真正的数据,key:默认是文件名,value:配置文件的内容
[[email protected] ~]# kubectl apply -f redis-conf.yml
configmap/redis-conf created
[[email protected] ~]#
查看ConfigMap
[[email protected] ~]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 2d1h
redis-conf 1 53s
[[email protected] ~]#
扩展: 查看redis-conf的yaml文件
kubectl get cm redis-conf -oyaml
创建pod
redis.yml
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis
command:
- redis-server
- "/redis-master/redis.conf" #指的是redis容器内部的位置
ports:
- containerPort: 6379
volumeMounts:
- mountPath: /data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: redis-conf
items:
- key: redis.conf
path: redis.conf
说明:一个ConfigMap文件可能有多个配置,items会遍历每个配置,key中定义这里要取哪个配置,path表示将取出来的配置文件内容放到容器内的哪个文件中。
关系图参考如下:

[[email protected] ~]# kubectl apply -f redis.yml
pod/redis created
# 进入到容器内部验证
[[email protected] ~]# kubectl exec -it redis -c redis -- /bin/bash
[email protected]:/data# cd /redis-master/
[email protected]:/redis-master# ls
redis.conf
[email protected]:/redis-master# cat redis.conf
appendonly yes
[email protected]:/redis-master#
修改ConfigMap
[[email protected] ~]# kubectl edit cm redis-conf
configmap/redis-conf edited
[[email protected] ~]#
添加了一行配置requirepass 123456。
[[email protected] ~]# kubectl exec -it redis -c redis -- /bin/bash
[email protected]:/data# cd /redis-master/
[email protected]:/redis-master# ls
redis.conf
[email protected]:/redis-master# cat redis.conf
appendonly yes
requirepass 123456
[email protected]:/redis-master#
ConfigMap被自动更新了。
重点说明:这里的自动更新只是容器内部的文件跟随ConfigMap的改变而改变,但是并不一定真正生效,主要看应用有没有热部署能力,没有热部署能力的应用需要重启才能生效。
删除ConfigMap
kubectl delete cm redis-conf
二、Secret
Secret 对象类型用来保存敏感信息,例如密码、OAuth 令牌和 SSH 密钥。 将这些信息放在 secret 中比放在 Pod 的定义或者 容器镜像 中来说更加安全和灵活。
创建Secret
# 命令格式
kubectl create secret docker-registry regcred \
--docker-server=<你的镜像仓库服务器> \
--docker-username=<你的用户名> \
--docker-password=<你的密码> \
--docker-email=<你的邮箱地址>
查看Secret
[[email protected] ~]# kubectl get secret
NAME TYPE DATA AGE
default-token-ssmvn kubernetes.io/service-account-token 3 2d2h
jiangnan kubernetes.io/dockerconfigjson 1 2m6s
[[email protected] ~]#
删除Secret
[[email protected] ~]# kubectl delete secret jiangnan
secret "jiangnan" deleted
[[email protected] ~]#
边栏推荐
- Pytorch through load_ state_ Dict load weight
- (perfect solution) how to set the position of Matplotlib legend freely
- Explanation of several points needing attention in final (tested by the author)
- SimpleITK学习笔记
- appium1.22.x 版本后的 appium inspector 需单独安装
- Redis expiration elimination mechanism
- (完美解决)matplotlib图例(legend)如何自由设置其位置
- Redis 击穿穿透雪崩
- (subplots用法)matplotlib如何绘制多个子图(轴域)
- Introduction to deep learning - definition Introduction (I)
猜你喜欢

BIO、NIO、AIO区别

音频焦点系列:手写一个demo理解音频焦点与AudioMananger

Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément

"250000 a year is just the price of cabbage" has become a thing of the past. The annual salary of AI posts has decreased by 8.9%, and the latest salary report has been released

Deep embedding and alignment of Google | protein sequences

大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南

Notepad++ wrap by specified character

Pan details of deep learning

Why is go language particularly popular in China

Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
随机推荐
2022.DAY592
6.23 warehouse operation on Thursday
Detailed explanation of yolov5 training own data set
Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
Calculation method of AUC
Redis expiration elimination mechanism
The IntelliJ platform completely disables the log4j component
Source insight License Activation
@Solutions to null pointer error caused by Autowired
Learn libcef together -- set cookies for your browser
Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
Deep embedding and alignment of Google | protein sequences
Go practice -- use redis in golang (redis and go redis / redis)
Robot capture experiment demonstration video
Introduction to redis and explanation of data types
Pytorch through load_ state_ Dict load weight
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
Installing altaro VM backup
(perfect solution) how to set the position of Matplotlib legend freely
Hotel public broadcasting background music - Design of hotel IP network broadcasting system based on Internet +