当前位置:网站首页>Kubernetes resource object introduction and common commands (V) - (configmap & Secret)
Kubernetes resource object introduction and common commands (V) - (configmap & Secret)
2022-07-05 20:29:00 【Silly [email protected]】
One 、ConfitMap
config set , Extract application configuration .
ConfigMap Save in kubernetes Of etcd in .
ConfigMap Can be file Mount directly to Pod Inside , Different from the previous article PV&PVC mount Catalog .
establish ConfigMap
Command line mode
[[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] ~]#
First of all, there is redis.conf file , Then make the document ConfigMap.
yaml The way ,redis-conf.yml
apiVersion: v1
data:
redis.conf: |
appendonly yes
kind: ConfigMap
metadata:
name: redis-conf
namespace: default
data Is all the real data ,key: The default is file name ,value: Content of profile
[[email protected] ~]# kubectl apply -f redis-conf.yml
configmap/redis-conf created
[[email protected] ~]#
see ConfigMap
[[email protected] ~]# kubectl get cm
NAME DATA AGE
kube-root-ca.crt 1 2d1h
redis-conf 1 53s
[[email protected] ~]#
Expand : see redis-conf Of yaml file
kubectl get cm redis-conf -oyaml
establish pod
redis.yml
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis
command:
- redis-server
- "/redis-master/redis.conf" # refer to redis Position inside the container
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
explain : One ConfigMap The file may have multiple configurations ,items Will traverse each configuration ,key Define which configuration to take here ,path Indicates which file in the container the content of the extracted configuration file is placed .
Refer to the diagram below :

[[email protected] ~]# kubectl apply -f redis.yml
pod/redis created
[[email protected] ~]#
# Go inside the container to verify
[[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#
modify ConfigMap
[[email protected] ~]# kubectl edit cm redis-conf
configmap/redis-conf edited
[[email protected] ~]#
Added a line of configuration 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 Automatically updated .
Key points : The automatic update here is just the file following inside the container ConfigMap To change , But it may not really take effect , It mainly depends on whether the application has hot deployment capability , Applications without hot deployment capability need to be restarted to take effect .
Delete ConfigMap
kubectl delete cm redis-conf
Two 、Secret
Secret Save in kubernetes Of etcd in .
Secret Object types are used to hold sensitive information , For example, password 、OAuth Token and SSH secret key . Put this information in secret Put the middle ratio in Pod It is more secure and flexible in the definition or container image .
establish Secret
# Command format
kubectl create secret docker-registry jiangnan \
--docker-server=< Your mirror warehouse server > \
--docker-username=< Your username > \
--docker-password=< Your password > \
--docker-email=< Your email address >
see 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] ~]#
Delete Secret
[[email protected] ~]# kubectl delete secret jiangnan
secret "jiangnan" deleted
[[email protected] ~]#
This paper is written by mdnice Multi platform Publishing
版权声明
本文为[Silly [email protected][email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207052006358350.html
边栏推荐
猜你喜欢
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
Leetcode brush questions: binary tree 11 (balanced binary tree)
Fundamentals - configuration file analysis
Guidelines for application of Shenzhen green and low carbon industry support plan in 2023
Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05
鸿蒙os第四次学习
Leetcode skimming: binary tree 16 (path sum)
港股将迎“最牛十元店“,名创优品能借IPO突围?
随机推荐
Codeforces Round #804 (Div. 2) - A, B, C
ICTCLAS word Lucene 4.9 binding
Mongodb basic exercises
Minimum commission for stock trading account opening, where to open an account with low commission? Is it safe to open an account on your mobile phone
Leetcode: binary tree 15 (find the value in the lower left corner of the tree)
About the priority of Bram IP reset
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
[C language] three implementations of quick sorting and optimization details
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
USACO3.4 “破锣摇滚”乐队 Raucous Rockers - DP
Schema and model
Document method
DP: tree DP
Practical demonstration: how can the production research team efficiently build the requirements workflow?
js实现禁止网页缩放(Ctrl+鼠标、+、-缩放有效亲测)
Zero cloud new UI design
Schema和Model
常用的视图容器类组件
Bzoj 3747 poi2015 kinoman segment tree
2020 CCPC Weihai - A. golden spirit (thinking), D. ABC project (big number decomposition / thinking)