tencent cloud

Tencent Kubernetes Engine

Release Notes and Announcements
Release Notes
Announcements
Release Notes
Product Introduction
Overview
Strengths
Architecture
Scenarios
Features
Concepts
Native Kubernetes Terms
Common High-Risk Operations
Regions and Availability Zones
Service Regions and Service Providers
Open Source Components
Purchase Guide
Purchase Instructions
Purchase a TKE General Cluster
Purchasing Native Nodes
Purchasing a Super Node
Getting Started
Beginner’s Guide
Quickly Creating a Standard Cluster
Examples
Container Application Deployment Check List
Cluster Configuration
General Cluster Overview
Cluster Management
Network Management
Storage Management
Node Management
GPU Resource Management
Remote Terminals
Application Configuration
Workload Management
Service and Configuration Management
Component and Application Management
Auto Scaling
Container Login Methods
Observability Configuration
Ops Observability
Cost Insights and Optimization
Scheduler Configuration
Scheduling Component Overview
Resource Utilization Optimization Scheduling
Business Priority Assurance Scheduling
QoS Awareness Scheduling
Security and Stability
TKE Security Group Settings
Identity Authentication and Authorization
Application Security
Multi-cluster Management
Planned Upgrade
Backup Center
Cloud Native Service Guide
Cloud Service for etcd
TMP
TKE Serverless Cluster Guide
TKE Registered Cluster Guide
Use Cases
Cluster
Serverless Cluster
Scheduling
Security
Service Deployment
Network
Release
Logs
Monitoring
OPS
Terraform
DevOps
Auto Scaling
Containerization
Microservice
Cost Management
Hybrid Cloud
AI
Troubleshooting
Disk Full
High Workload
Memory Fragmentation
Cluster DNS Troubleshooting
Cluster kube-proxy Troubleshooting
Cluster API Server Inaccessibility Troubleshooting
Service and Ingress Inaccessibility Troubleshooting
Common Service & Ingress Errors and Solutions
Engel Ingres appears in Connechtin Reverside
CLB Ingress Creation Error
Troubleshooting for Pod Network Inaccessibility
Pod Status Exception and Handling
Authorizing Tencent Cloud OPS Team for Troubleshooting
CLB Loopback
API Documentation
History
Introduction
API Category
Making API Requests
Elastic Cluster APIs
Resource Reserved Coupon APIs
Cluster APIs
Third-party Node APIs
Relevant APIs for Addon
Network APIs
Node APIs
Node Pool APIs
TKE Edge Cluster APIs
Cloud Native Monitoring APIs
Scaling group APIs
Super Node APIs
Other APIs
Data Types
Error Codes
TKE API 2022-05-01
FAQs
TKE General Cluster
TKE Serverless Cluster
About OPS
Hidden Danger Handling
About Services
Image Repositories
About Remote Terminals
Event FAQs
Resource Management
Service Agreement
TKE Service Level Agreement
TKE Serverless Service Level Agreement
Contact Us
Glossary

ConfigMap Management

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2024-12-19 22:09:58

Overview

ConfigMap allows you to decouple configuration artifacts from images to ensure that the application is more portable. ConfigMap is a key-value pair. You can create a corresponding ConfigMap object using kubectl in the console, and use a ConfigMap by mounting a volume, through environment variables, or in the container's run command.

Using the Console

Creating a ConfigMap

1. Log in to the TKE console.
2. In the left sidebar, click Cluster to open the TKE cluster list page.
3. Click the ID of the cluster where ConfigMap needs to be created to go to the cluster management page.
4. Select Configuration Management > ConfigMap to go to the ConfigMap information page.
5. Click Create to go to the Create ConfigMap page.
6. Set the ConfigMap parameters based on actual needs. Key parameters are as follows:
Name: customize the name of the container in the Pod.
Namespace: Select the namespace type and set the variable name and value based on actual needs.
Content: Add the variable name and variable value.
7. Click Create ConfigMap.

Using a ConfigMap

Method 1: Using the ConfigMap Type for a Volume

1. Log in to the TKE console.
2. In the left sidebar, click Cluster to open the TKE cluster list page.
3. Click the ID of the cluster where Workload needs to be deployed to go to the cluster management page.
4. Under Workload, select any workload type to go to the relevant information page. For example, select Workload > DaemonSet to go to the DaemonSet information page.
5. Click Create to go to the Create DaemonSet page.
6. Set the workload name, namespace and other information as instructed. In Volume, click Add Volume.


7. In the Add volume pop-up window, configure the mounting point and click OK. Set Data volume type to Use ConfigMap, enter the volume name, and click the Select ConfigMap drop-down list to select an option.


Data volume type: Select Use ConfigMap.
Volume name: Enter a custom name.
Select ConfigMap: Select as needed.
Options: All and Specific keys are available.
Items: if you select Specific keys, you can mount to a specific path by adding an item. For example, if the mounting point is /data/config, and the file name is filename, the value of the key-value pair will be stored under /data/config/filename.
8. Click OK. Click Create Workload.

Method 2: Using the ConfigMap Type for an Environmental Variable

1. Log in to the TKE console.
2. In the left sidebar, click Cluster to open the TKE cluster list page.
3. Click the ID of the cluster where Workload needs to be deployed to go to the cluster management page.
4. Under Workload, select any workload type to go to the relevant information page. For example, select Workload > DaemonSet to go to the DaemonSet information page.
5. Click Create to go to the Create DaemonSet page.
6. Set the workload name, namespace and other information as instructed. In Environment Variable under Containers in the Pod, click Add variable.


7. Select "ConfigMap" for the environment variable and select the resource based on actual needs.
8. Click Create Workload to complete the process.

Updating a ConfigMap

1. Log in to the TKE console.
2. In the left sidebar, click Cluster to open the TKE cluster list page.
3. Click the ID of the cluster where ConfigMap needs to be updated to go to the cluster management page.
4. Select Configuration Management > ConfigMap to go to the ConfigMap information page.
5. Click Update configuration in the Operation column of the ConfigMap whose configuration needs to be updated.


6. On the Update configuration page, edit the key-value pair and click Update ConfigMap.



Via kubectl

YAML sample

apiVersion: v1
data:
key1: value1
key2: value2
key3: value3
kind: ConfigMap
metadata:
name: test-config
namespace: default

data: The data of ConfigMap presented as key-value.
kind: This identifies the ConfigMap resource type.
metadata: Basic information such as ConfigMap name and Label.
metadata.annotations: An additional description of the ConfigMap. You can set additional enhancements to TKE through this parameter.

Creating a ConfigMap

Method 1: Creating Using the YAML Sample File

1. See the YAML sample to prepare the ConfigMap YAML file.
2. Install kubectl and connect to a cluster. For detailed operations, see Connecting to a Cluster.
3. Run the following command to create the ConfigMap YAML file.
kubectl create -f ConfigMap YAML filename
For example, to create a ConfigMap YAML file named web.yaml, run the following command:
kubectl create -f web.yaml
4. Run the following command to check whether the Job is successfully created.
kubectl get configmap
If a message similar to the following is returned, the creation is successful.
NAME DATA AGE
test 2 39d
test-config 3 18d

Method 2: Creating by Running a Command

Run the following command to create the ConfigMap in the directory.
kubectl create configmap <map-name> <data-source>
<map-name>: Name of the ConfigMap.
<data-source>: Directory, file, or literal.
For more details about the parameters, see Kubernetes' official document about ConfigMap.

Using a ConfigMap

Method 1: Using the ConfigMap Type for a Volume

Below is a YAML sample:
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:latest
volumeMounts:
name: config-volume
mountPath: /etc/config
volumes:
name: config-volume
configMap:
name: test-config ## Set the ConfigMap source
## items: ## Set the key mounting of the specified ConfigMap
## key: key1 ## Select the specified key
## path: keys ## Mount to the specified subpath
restartPolicy: Never

Method 2: Using the ConfigMap Type for an Environmental Variable

Below is a YAML sample:
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:latest
env:
- name: key1
valueFrom:
configMapKeyRef:
name: test-config ## Set the filename of the source ConfigMap
key: test-config.key1 ## Set the value source of the environment variable
restartPolicy: Never


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan