当前位置:网站首页>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] ~]#
边栏推荐
猜你喜欢
穀歌 | 蛋白序列的深度嵌入和比對
Introduction to redis using Lua script
Final review (Day5)
ES7 easy mistakes in index creation
Disassembly and installation of Lenovo r7000 graphics card
kubernetes资源对象介绍及常用命令(五)-(ConfigMap)
小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()
Redis cannot connect remotely.
Analysis of the example of network subnet division in secondary vocational school
随机推荐
Differences among bio, NiO and AIO
[untitled]
kubernetes资源对象介绍及常用命令(五)-(ConfigMap)
Best practices for setting up altaro VM backups
mysql启动报错:The server quit without updating PID file几种解决办法
穀歌 | 蛋白序列的深度嵌入和比對
Introduction to deep learning (II) -- univariate linear regression
ninja: build stopped: subcommand failed.
Final review (Day7)
期末复习DAY8
Introduction to rust Foundation (basic type)
Go practice -- closures in golang (anonymous functions, closures)
Introduction to webrtc protocol -- an article to understand dtls, SRTP, srtcp
Altaro VM backup getting started
Technical analysis of qianyuantong multi card aggregation router
Go practice -- gorilla / websocket used by gorilla web Toolkit
6.23星期四库作业
The request database reported an error: "could not extract resultset; SQL [n/a]; needed exception is org.hibernate.exception.sqlgram"
期末复习(DAY7)
Final review Day8