当前位置:网站首页>Kubernetes notes (V) configuration management
Kubernetes notes (V) configuration management
2022-07-03 05:59:00 【Ashley shot the sun】
List of articles
1. ConfigMap
ConfigMap It's a kind of API object , Used to save unclassified data to a health value pair . When used, it can be used as an environment variable 、 Command line parameters or configuration files in the storage volume .ConfigMap The configuration information can be decoupled from the container image , It is convenient to modify the application configuration . Every time the application needs to modify the configuration , It just needs to be modified ConfigMap Then restart the application on demand Pod that will do , There is no need to recompile and package like modifying code 、 Make image and other operations .
Kubernetes Support literal based 、 file 、 Create by directory, etc ConfigMap, The following is an example based on literal quantity
kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm
$ kubectl get configmaps special-config -o yaml
apiVersion: v1
kind: ConfigMap
metadata:
creationTimestamp: 2016-02-18T19:14:38Z
name: special-config
namespace: default
resourceVersion: "651"
selfLink: /api/v1/namespaces/default/configmaps/special-config
uid: dadce046-d673-11e5-8cd0-68f728db1985
data:
special.how: very
special.type: charm
ConfigMap After creation, it can be directly mounted as a volume to Pod , It can also be used to declare environment variables :
Use as an environment variable
You can introduce the specified key value pairs as environment variables , You can also introduce all key value pairs as environment variables .
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "env" ]
env:
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.how
envFrom:
- configMapRef:
name: special-config
restartPolicy: Never
Mount the volume directly
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "ls /etc/config/" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
name: special-config
restartPolicy: Never
2. Secret
ConfigMap It is generally used to manage and store common configurations , and Secret It is used to manage and save sensitive information , For example, password ,OAuth token , Or is it ssh Key, etc . Use Secret To save this information will be more dynamically added to Pod Define or use ConfigMap More security and flexibility .
and ConfigMap equally ,Secret It also supports literal based 、 File, etc , Then mount into Pod in .
Creating Secret when Kubernetes Different types are available :
$ kubectl create secret
Create a secret using specified subcommand.
Available Commands:
docker-registry Create a secret for use with a Docker registry
generic Create a secret from a local file, directory, or literal value
tls Create a TLS secret
Generic Generic type , It can be based on files 、 Literal 、 directories creating .
tls Used to create TLS Encryption with Secret, You need to specify the key And certificates , For example, refer to our Ingress Enable TLS
docker-registry: Create access to the private image repository Secret, The authentication information needed to access the image warehouse can be encapsulated in Secret. Then when Pod You can use this... When the image in needs to be pulled from the private image warehouse Secret 了 .
$
kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
apiVersion: v1
kind: Pod
metadata:
name: private-reg
spec:
containers:
- name: private-reg-container
image: <your-private-image>
imagePullSecrets:
- name: regcred
---
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: redis
volumeMounts:
- name: foo
mountPath: "/etc/foo"
volumes:
- name: foo
secret:
secretName: mysecret
defaultMode: 0400
For ordinary Secret, Can be like ConfigMap As an environment variable or volume in Pod Use in .
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: redis
volumeMounts:
- name: foo
mountPath: "/etc/foo"
volumes:
- name: foo
secret:
secretName: mysecret
defaultMode: 0400
Secret The values stored in are all after base64 Encoded value
$ kubectl create secret generic prod-db-secret \
--from-literal=username=produser \
--from-literal=password=Y4nys7f11
secret/prod-db-secret created
username: 8 bytes
$ kubectl get secrets prod-db-secret -o yaml
apiVersion: v1
data:
password: WTRueXM3ZjEx
username: cHJvZHVzZXI=
kind: Secret
metadata:
name: prod-db-secret
namespace: default
type: Opaque
$ echo "WTRueXM3ZjEx" | base64 -d
Y4nys7f11%
$ echo "cHJvZHVzZXI=" | base64 -d
produser%
So we just need to get Secret It can be done by base64 Decode and obtain the value of the actual sensitive data . therefore Secret The security provided by itself is limited , More around Secret Safety practices . For example, avoid writing sensitive data directly to the code warehouse , So... Is extracted Secret. In addition, there is only one node Pod be used Secret It will be sent to the corresponding node , You can set Secret Write to memory instead of disk , such Pod After the stop Secret Data will also be deleted .
Kubernetes Components and api-server Communication between is generally subject to TLS The protection of , therefore Secret It is also safe when transferring between components .Pod Can't share between Secret, Can be in Pod Level build security partitions to ensure that only required containers can access Secret.
边栏推荐
- Today, many CTOs were killed because they didn't achieve business
- Bio, NiO, AIO details
- Linux登录MySQL出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
- 多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
- Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11
- [escape character] [full of dry goods] super detailed explanation + code illustration!
- 期末复习(DAY6)
- Complete set of C language file operation functions (super detailed)
- 【无标题】
- JS implements the problem of closing the current child window and refreshing the parent window
猜你喜欢
![[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb](/img/cc/5509b62756dddc6e5d4facbc6a7c5f.jpg)
[teacher Zhao Yuqiang] calculate aggregation using MapReduce in mongodb
![[function explanation (Part 1)] | | knowledge sorting + code analysis + graphic interpretation](/img/c2/991b8febd262cf9237017adc9d1221.jpg)
[function explanation (Part 1)] | | knowledge sorting + code analysis + graphic interpretation

Understand expectations (mean / estimate) and variances

Kubernetes resource object introduction and common commands (V) - (configmap)

Qt读写Excel--QXlsx插入图表5
![[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history](/img/18/f91d3d21a39743231d01f2e4015ef8.jpg)
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history

Alibaba cloud OOS file upload

Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)

Linux登录MySQL出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
随机推荐
If function of MySQL
[advanced pointer (2)] | [function pointer, function pointer array, callback function] key analysis + code explanation
1. Somme des deux nombres
Alibaba cloud Alipay sandbox payment
2022.DAY592
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
智牛股项目--04
[function explanation (Part 1)] | | knowledge sorting + code analysis + graphic interpretation
[teacher Zhao Yuqiang] MySQL flashback
【无标题】
Ansible firewall firewalld setting
Kubernetes resource object introduction and common commands (V) - (configmap)
【一起上水硕系列】Day 7 内容+Day8
Redhat7系统root用户密码破解
2022.7.2day594
[video of Teacher Zhao Yuqiang's speech on wot] redis high performance cache and persistence
Alibaba cloud OOS file upload
理解 期望(均值/估计值)和方差
Jedis source code analysis (II): jediscluster module source code analysis
Apt update and apt upgrade commands - what is the difference?