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--
ConfigMap is a quick way to modify variables in the container, which is composed of KMV.When you modify configmap, the variables in the container will be modified accordingly.
View help documentation
[root@node-1 ~] # kubectl explain pod.spec.containers.env.valueFrom.configMapKeyRef [root @ node-1 ~] # kubectl explain configmap
Configmap can be created directly with the command or you can save the value to a file, where the file name is key and the contents of the file are value.
Directly use the command:
[root@node-1 ~] # kubectl create configmap-- help kubectl create configmap nginx-nc-- from-literal=nginx_port=80-- from-literal=nginx_server=erick.com View the created cm [root @ node-1 ~] # kubectl get cmNAME DATA AGEnginx-nc 2 60s [root @ node-1 cm] # kubectl get cm nginx-nc-o yamlapiVersion: v1data: nginx_port: "80" nginx_server: erick.comkind: ConfigMapmetadata: creationTimestamp: "2019-06-20T22: 34selfLink: / api/v1/namespaces/default/configmaps/nginx-nc uid: 9a180b6e-93ab-11e9-b0ae-080027edb92f [root@node-1 cm] # name: nginx-nc namespace: default resourceVersion: "432545"
Store the value as a file
} [root@node-1 cm] # kubectl create configmap nginx-cm-from-file-- from-file=./www.conf configmap/nginx-cm-from-file created [root @ node-1 cm] # kubectl get cmNAME DATA AGEnginx-cm-from-file 1 7snginx-nc 2 9m7s [root @ node-1 cm] # kubectl get cm nginx-cm-from-file-o yamlapiVersion: v1data: www.conf: "server {\ n\ tserver_name myapp.com \ n\ n}\ n "kind: ConfigMapmetadata: creationTimestamp:" 2019-06-20T22:43:44Z "name: nginx-cm-from-file namespace: default resourceVersion:" 433432 "selfLink: / api/v1/namespaces/default/configmaps/nginx-cm-from-file uid: dbd2aa33-93ac-11e9-b0ae-080027edb92f [root@node-1 cm] # you can also see [root@node-1 cm] # kubectl describe cm nginx-ncName: nginx-ncNamespace with describe: DefaultLabels: Annotations: Data====nginx_port:----80nginx_server:----erick.comEvents: [root@node-1 cm] # kubectl describe cm nginx-cm-from-fileName: nginx-cm-from-fileNamespace: defaultLabels: Annotations: Data====www.conf:----server {server_name myapp.com Port 80; root / data/web/html;} Events:
Create a pod association with the cm you just created
[root@node-1 cm] # cat cm-1.yml apiVersion: v1kind: Podmetadata: name: myapp-cm-1 namespace: default annotations: erick: "by erick" spec: containers:-name: myapp-cm-1 image: ikubernetes/myapp:v1 ports:-name: http containerPort: 80 env:-name: nginx_port valueFrom: configMapKeyRef: name: nginx-nc key: nginx_port -name: nginx_server valueFrom: configMapKeyRef: name: nginx-nc key: nginx_ server [root @ node-1 cm] #
Enter the container and view the environment variables
[root@node-1 cm] # kubectl get podNAME READY STATUS RESTARTS AGEmyapp-cm-1 1 kubectl get podNAME READY STATUS RESTARTS AGEmyapp-cm-1 1 Running 0 2m16s [root @ node-1 cm] # kubectl exec-it myapp-cm-1-/ bin/sh/ # env | grep nginx_portnginx_port=80/ # env | grep nginx_servernginx_server=erick.com/ #
Let's modify the environment variable of cm
[root@node-1 cm] # kubectl edit configmap nginx-nc# Please edit the object below. If an error occurs while saving this file will be# reopened with the relevant failures.#apiVersion: v1data: nginx_port: "8080" nginx_server: erick.comkind: ConfigMapmetadata: creationTimestamp: "2019-06-20T22:34:44Z" name: nginx-nc namespace: default resourceVersion: "436267" selfLink: / api/v1/namespaces/default/configmaps/nginx-nc uid: 9a180b6eMuth93abmur11e9Murb0aeMuy080027edb92f~ Modify port to 8080 and check again whether the environment variable changes [root@node-1 cm] # kubectl exec-it myapp-cm-1-/ bin/sh/ # env | grep nginx_portnginx_port=80/ #
Conclusion: the environment variables in pod will only take effect when they are first created, even if you restart pod, they will not take effect, and later changes will not take effect.
two. Pod references environment variables based on the storage volume.
ApiVersion: v1kind: Podmetadata: name: myappcmwww namespace: default annotations: erick: "by erick" spec: containers:-name: myappcmwww image: ikubernetes/myapp:v1 ports:-name: http containerPort: 80 volumeMounts:-name: nginx-conf mountPath: / etc/nginx/conf.d/ volumes:-name: nginx-conf configMap: name: nginx-cm-from-file [root@node-1 cm] # enter the container Check the environment variable [root@node-1 cm] # kubectl exec-it myappcmwww-/ bin/sh/ # cat / etc/nginx/conf.d/..2019_06_22_09_11_04.278015527/.. data/ www.conf/ # cat / etc/nginx/conf.d/www.conf server {server_name myapp.com Listen 80; root / data/web/html;} / #
Modify the port of configmap to 8080
[root@node-1] # kubectl edit cm nginx-cm-from-file# Please edit the object below. Lines beginning with a'# 'will be ignored,# and an empty file will abort the edit. If an error occurs while saving this file will be# reopened with the relevant failures.#apiVersion: v1data: www.conf: "server {\ n\ tserver_name myapp.com;\ n\ tlisten 8080;\ n\ troot / data/web/html \ n\ n}\ n "kind: ConfigMapmetadata: creationTimestamp:" 2019-06-20T22:43:44Z "name: nginx-cm-from-file namespace: default resourceVersion:" 494403 "selfLink: / api/v1/namespaces/default/configmaps/nginx-cm-from-file uid: dbd2aa33-93ac-11e9-b0ae-080027edb92f check inside the container to see if the environment variable has changed. / # cat / etc/nginx/conf.d/www.conf server {server_name myapp.com; listen 8080; root / data/web/html;} /
Has changed dynamically.
Secret
Secret is a format encoded in base64
[root@node-1 cm] # kubectl create secret-- help [root @ node-1 cm] # kubectl create secret-- helpCreate 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 when linking a private image Directory or literal value # # when storing passwords, tls Create a TLS secret # # when placing certificates, Usage: kubectl create secret [flags] [options] Use "kubectl-help" for more information about a given command.Use "kubectl options" for a list of global command-line options (applies to all commands). [root@node-1 cm] #
Secrete is encrypted with bash74 and can be decrypted in reverse.
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.