当前位置:网站首页>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
边栏推荐
- sun. misc. Base64encoder error reporting solution [easy to understand]
- . Net distributed transaction and landing solution
- 港股将迎“最牛十元店“,名创优品能借IPO突围?
- Schema and model
- 【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)
- Is it safe for Galaxy Securities to open an account online?
- 关于BRAM IP复位的优先级
- Leetcode brush question: binary tree 13 (the same tree)
- Leetcode skimming: binary tree 10 (number of nodes of a complete binary tree)
- Oracle-表空间管理
猜你喜欢
实操演示:产研团队如何高效构建需求工作流?
A solution to PHP's inability to convert strings into JSON
Enter the parallel world
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
死信队列入门(两个消费者,一个生产者)
Fundamentals - configuration file analysis
JS implementation prohibits web page zooming (ctrl+ mouse, +, - zooming effective pro test)
物联网智能家居基本方法实现之经典
.Net分布式事務及落地解决方案
Welcome to the game and win rich bonuses: Code Golf Challenge officially launched
随机推荐
基金网上开户安全吗?去哪里开,可以拿到低佣金?
Oracle-表空间管理
Leetcode(347)——前 K 个高频元素
How to retrieve the root password of MySQL if you forget it
CVPR 2022 | common 3D damage and data enhancement
Codeforces Round #804 (Div. 2) - A, B, C
[C language] merge sort
Scala basics [HelloWorld code parsing, variables and identifiers]
c語言oj得pe,ACM入門之OJ~
Y57. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (30)
3.3、项目评估
Codeforces Round #804 (Div. 2) - A, B, C
document方法
2.8 basic knowledge of project management process
Leetcode skimming: binary tree 16 (path sum)
Classic implementation of the basic method of intelligent home of Internet of things
CVPR 2022 | 常见3D损坏和数据增强
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
走入并行的世界
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)