当前位置:网站首页>Kubernetes resource object introduction and common commands (V) - (configmap)
Kubernetes resource object introduction and common commands (V) - (configmap)
2022-07-03 05:37:00 【Jiang Xiaonan】
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
# 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 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 The definition of or Container mirror More secure and flexible in .
establish Secret
# Command format
kubectl create secret docker-registry regcred \
--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] ~]#
边栏推荐
- PHP笔记超详细!!!
- Bluebridge cup real topic 2020 palindrome date simulation construction provincial competition
- 期末复习(DAY7)
- 2022.7.2day594
- Rust基础入门之(基本类型)
- Map的扩容机制
- Go practice -- generate and read QR codes in golang (skip2 / go QRcode and boombuilder / barcode)
- Apache+PHP+MySQL环境搭建超详细!!!
- Redis expiration elimination mechanism
- Latest version of source insight
猜你喜欢
Sophomore dilemma (resumption)
redis 无法远程连接问题。
[set theory] relational closure (relational closure related theorem)
Gan network thought
穀歌 | 蛋白序列的深度嵌入和比對
Brief introduction of realsense d435i imaging principle
Progressive multi grasp detection using grasp path for rgbd images
How to use source insight
Introduction to deep learning (II) -- univariate linear regression
DEX net 2.0 for crawl detection
随机推荐
Rust基础入门之(基本类型)
Detailed explanation of yolov5 training own data set
今天很多 CTO 都是被幹掉的,因為他沒有成就業務
Basic introduction of redis and explanation of eight types and transactions
[untitled]
Deep embedding and alignment of Google | protein sequences
Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
Yolov5 model construction source code details | CSDN creation punch in
Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit
PHP笔记超详细!!!
Source insight License Activation
XML Configuration File
Simpleitk learning notes
ansible防火墙firewalld设置
DEX net 2.0 for crawl detection
Analysis of the example of network subnet division in secondary vocational school
Skip table: principle introduction, advantages and disadvantages of skiplist
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
Today, many CTOs were killed because they didn't achieve business
Intégration profonde et alignement des séquences de protéines Google