Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The use of ConfigMap in Kubernetes

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

As the name implies, ConfigMap is used to hold key-value pairs of configuration data, either to save individual properties or to save configuration files.

ConfigMap is similar to another concept of Kubernetes, secret, except that ConfigMap is mainly used to hold plaintext strings that do not contain sensitive information.

Creation method:

Kubectl create configmap special-config-from-literal=i042416=jerry

The above command line creates a key-value pair named special-config

Key is i042416, value is jerry

Next I want to define an environment variable in pod with the value "jerry" with key of i042416.

Here is my yaml file:

ApiVersion: v1

2 kind: Pod

3 metadata:

4 name: jerry-config-pod

5 spec:

6 containers:

7-name: test-container

8 image: gcr.io/google_containers/busybox

9 command: ["/ bin/sh", "- c", "env"]

10 env:

11-name: JERRY_NAME

12 valueFrom:

13 configMapKeyRef:

14 name: special-config

15 key: i042416

16 restartPolicy: Never

You can see that line 15 refers to my ConfigMap's key:i042416

Let's import the yaml file using create-f to create a new pod:

After creation, you can see that the key of configMap has been displayed as an environment variable on the details page of pod:

Because my yaml file specifies that the script executed by pod is / bin/sh-c env, all the environment variables in the container are finally printed, and the value jerry of i042416, which we defined in ConfigMap, is also displayed:

This practice of defining environment variables is similar to the way environment variables are defined in the CloudFoundry environment of the SAP cloud platform.

List of CloudFoundry environment variables:

Https://docs.run.pivotal.io/devguide/deploy-apps/environment-variable.html

CF_INSTANCE_ADDR

CF_INSTANCE_GUID

CF_INSTANCE_INDEX

CF_INSTANCE_IP

CF_INSTANCE_INTERNAL_IP

CF_INSTANCE_PORT

CF_INSTANCE_PORTS

DATABASE_URL

HOME

LANG

MEMORY_LIMIT

PORT

PWD

TMPDIR

USER

VCAP_APP_PORT

VCAP_APPLICATION

VCAP_SERVICES

When the local application is deployed to the CloudFoundry environment of the SAP cloud platform using the cf push command, some environment variables are automatically written to the corresponding values by the system, which has the same logic as the sy-sysid of ABAP is automatically set to the current system ID.

For example, app router redirects user access requests to the XSUAA instance.

The name of the XSUAA instance defined by app router in manifest.yml is xsuaa-jerry-demo

At run time, the id of this XSUAA will be automatically written into the environment variable VCAP_SERVICES by the SAP cloud platform:

For more original articles by Jerry, please follow the official account "Wang Zixi"

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report