当前位置:网站首页>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] ~]#
边栏推荐
- @Autowired 导致空指针报错 解决方式
- "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
- SimpleITK学习笔记
- appium1.22.x 版本後的 appium inspector 需單獨安裝
- The IntelliJ platform completely disables the log4j component
- Detailed explanation of yolov5 training own data set
- How to set up altaro offsite server for replication
- Explanation of variables, code blocks, constructors, static variables and initialization execution sequence of static code blocks of Ali interview questions
- Deploy crawl detection network using tensorrt (I)
- Yolov5 network structure + code + application details | CSDN creation punch in
猜你喜欢

Simpleitk learning notes

Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn

"C and pointer" - Chapter 13 function of function pointer 1 - callback function 1

期末复习(Day5)

Differences among bio, NiO and AIO

Deep embedding and alignment of Google | protein sequences

About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller

6.23 warehouse operation on Thursday
![[basic grammar] Snake game written in C language](/img/cb/83631ef3ccd7047ca42d33dc49bf90.jpg)
[basic grammar] Snake game written in C language

How to use source insight
随机推荐
期末复习(day3)
Shanghai daoning, together with American /n software, will provide you with more powerful Internet enterprise communication and security component services
Installing altaro VM backup
Intégration profonde et alignement des séquences de protéines Google
Chapter II program design of circular structure
Deploy crawl detection network using tensorrt (I)
Explanation of variables, code blocks, constructors, static variables and initialization execution sequence of static code blocks of Ali interview questions
appium1.22.x 版本後的 appium inspector 需單獨安裝
ninja: build stopped: subcommand failed.
Map的扩容机制
在PyCharm中配置使用Anaconda环境
[set theory] relational closure (relational closure related theorem)
Yolov5 model construction source code details | CSDN creation punch in
Export the altaro event log to a text file
Webrtc native M96 version opening trip -- a reading code download and compilation (Ninja GN depot_tools)
Why is go language particularly popular in China
微服务常见面试题
6.23星期四库作业
Training method of grasping angle in grasping detection
Altaro set grandfather parent child (GFS) archiving