当前位置:网站首页>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
边栏推荐
- - Oui. Net Distributed Transaction and Landing Solution
- Document method
- What is PyC file
- y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
- 3.3 project evaluation
- Bzoj 3747 poi2015 kinoman segment tree
- [quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
- IC科普文:ECO的那些事儿
- Scala基础【HelloWorld代码解析,变量和标识符】
- Mongodb basic exercises
猜你喜欢

- Oui. Net Distributed Transaction and Landing Solution

1. Strengthen learning basic knowledge points

物联网智能家居基本方法实现之经典

鸿蒙os第四次学习
![Ros2 topic [01]: installing ros2 on win10](/img/46/550945aa36d2bec03e5dd29404f409.png)
Ros2 topic [01]: installing ros2 on win10

Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms

【刷题记录】1. 两数之和

【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)

Leetcode brush question: binary tree 14 (sum of left leaves)
![[record of question brushing] 1 Sum of two numbers](/img/ea/4e981edd5570b49b4fa909ac8da6c4.png)
[record of question brushing] 1 Sum of two numbers
随机推荐
Process file and directory names
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
3.3 project evaluation
Informatics Olympiad 1338: [example 3-3] hospital setting | Luogu p1364 hospital setting
Applet global configuration
2.8 basic knowledge of project management process
Composition of applet code
Is it safe for CICC fortune to open an account online?
2022 Beijing eye health products exhibition, eye care products exhibition, China eye Expo held in November
Is it safe for Galaxy Securities to open an account online?
About the priority of Bram IP reset
实操演示:产研团队如何高效构建需求工作流?
Applet event binding
Wechat applet regular expression extraction link
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
Leetcode (695) - the largest area of an island
【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
插值查找的简单理解
基金网上开户安全吗?去哪里开,可以拿到低佣金?
【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)