In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
One: brief introduction
The configuration of applications in many production environments is complex and may require a combination of multiple config files, command-line arguments, and environment variables. When using container deployment, the configuration should be decoupled from the application image to ensure the portability of the image.
ConfigMap is the kubernetes resource object used to store configuration files, and all configuration content is stored in etcd. ConfigMap allows us to decouple the configuration details from the container image. Through ConfigMap, we can pass the configuration to container or other system components (such as Controller) in the form of key-value pairs.
Second: the way to create ConfigMap
1.From Literal Values can use kubectl create to create a ConfigMap, and then get it through kubectl get
Click (here) to collapse or open
# Create the ConfigMap
$kubectl create configmap my-config-from-literal=key1=value1-from-literal=key2=value2
Configmap "my-config" created
# Get the ConfigMap Details for my-config
$kubectl get configmaps my-config-o yaml
ApiVersion: v1
Data:
Key1: value1
Key2: value2
Kind: ConfigMap
Metadata:
CreationTimestamp: 2017-05-31T07:21:55Z
Name: my-config
Namespace: default
ResourceVersion: "241345"
SelfLink: / api/v1/namespaces/default/configmaps/my-config
Uid: d35f0a3d-45d1-11e7-9e62-080027a460572.From Configuration File is created directly through the configuration file
Click (here) to collapse or open
ApiVersion: v1
Kind: ConfigMap
Metadata:
Name: special-config
Namespace: default
Data:
Special.how: very
Click (here) to collapse or open
ApiVersion: v1
Kind: ConfigMap
Metadata:
Name: env-config
Namespace: default
Data:
Log_level: INFO3. The current directory contains if there is a configuration file donkey.properties, you can use the kubectl command to create a ConfigMap containing the contents of the file.
Kubectl create configmap donkey.properties-from-file=donkey.properties
Third: the use of ConfigMap
1.Pod uses ConfigMap to define environment variables through env
Click (here) to collapse or open
ApiVersion: v1
Kind: Pod
Metadata:
Name: dapi-test-pod
Spec:
Containers:
-name: test-container
Image: gcr.io/google_containers/busybox
Command: ["/ bin/sh", "- c", "env"]
Env:
-name: SPECIAL_LEVEL_KEY
ValueFrom:
ConfigMapKeyRef:
Name: special-config
Key: special.how
-name: LOG_LEVEL
ValueFrom:
ConfigMapKeyRef:
Name: env-config
Key: log_level
RestartPolicy: Never starts with Kubernetes V1.6 and introduces a new field, envFrom, to automatically generate environment variables for key=value defined in ConfigMap in the Pod environment:
Click (here) to collapse or open
ApiVersion: v1
Kind: Pod
Metadata:
Name: dapi-test-pod
Spec:
Containers:
-name: test-container
Image: gcr.io/google_containers/busybox
Command: ["/ bin/sh", "- c", "env"]
EnvFrom:
-configMapRef:
Name: special-config
RestartPolicy: Never
two。 Use ConfigMap to set the startup parameters of the container startup command
Click (here) to collapse or open
ApiVersion: v1
Kind: Pod
Metadata:
Name: dapi-test-pod
Spec:
Containers:
-name: test-container
Image: k8s.gcr.io/busybox
Command: ["/ bin/sh", "- c", "echo $(SPECIAL_LEVEL_KEY) $(SPECIAL_TYPE_KEY)"]
Env:
-name: SPECIAL_LEVEL_KEY
ValueFrom:
ConfigMapKeyRef:
Name: special-config
Key: SPECIAL_LEVEL
-name: SPECIAL_TYPE_KEY
ValueFrom:
ConfigMapKeyRef:
Name: special-config
Key: SPECIAL_TYPE
RestartPolicy: Never3. Using ConfigMap in storage volumes
Click (here) to collapse or open
ApiVersion: v1
Kind: Pod
Metadata:
Name: busybox
Namespace: default
Spec:
Containers:
-image: 120.79.156.135/desktop/busybox:latest
Command:
-sleep
-"3600"
ImagePullPolicy: IfNotPresent
Name: busybox
VolumeMounts:
-name: donkeyconfig
MountPath: / configfiles
Volumes:
-name: donkeyconfig
ConfigMap:
Name: donkey.properties
Items:
-key: donkey.properties
Path: donkey.properties
RestartPolicy: Always
ImagePullSecrets:
-name: registry- secret4: restrictions on using ConfigMap
1.ConfigMap must be created before Pod
2.ConfigMap is restricted by Namespace, and only Pod in the same Namespaces can reference it.
Quota management in 3.ConfigMap has not been implemented yet
4.kubelet only supports ConfigMap for Pod that can be managed by API Server.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.