configMapのK8S

configMapはconfigmapコンテナ変数を変更することもそれに応じて変更されたとき、容器の変数を変更する簡単な方法で、組成KV。
私たちのヘルプドキュメント

[root@node-1 ~]# kubectl explain pod.spec.containers.env.valueFrom.configMapKeyRef

[root@node-1 ~]# kubectl explain configmap

configmapは、ファイルの内容が値に、直接値も、ファイルにキーという名前のファイルを保存することができます作成注文することができます。
直接コマンドで:

[root@node-1 ~]# kubectl create configmap --help
 kubectl create configmap nginx-nc --from-literal=nginx_port=80 --from-literal=nginx_server=erick.com
 查看创建的cm
[root@node-1 ~]# kubectl get cm
NAME       DATA   AGE
nginx-nc   2      60s
[root@node-1 cm]# kubectl get cm nginx-nc -o yaml
apiVersion: v1
data:
  nginx_port: "80"
  nginx_server: erick.com
kind: ConfigMap
metadata:
  creationTimestamp: "2019-06-20T22:34:44Z"
  name: nginx-nc
  namespace: default
  resourceVersion: "432545"
  selfLink: /api/v1/namespaces/default/configmaps/nginx-nc
  uid: 9a180b6e-93ab-11e9-b0ae-080027edb92f
[root@node-1 cm]# 

ファイルに格納された値

[root@node-1 cm]# cat www.conf 
server {
        server_name myapp.com;
        port 80;
        root /data/web/html;

}
[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 cm
NAME                 DATA   AGE
nginx-cm-from-file   1      7s
nginx-nc             2      9m7s
[root@node-1 cm]# kubectl get cm nginx-cm-from-file -o yaml
apiVersion: v1
data:
  www.conf: "server {\n\tserver_name myapp.com;\n\tport 80;\n\troot /data/web/html;\n\n}\n"
kind: ConfigMap
metadata:
  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]# 
也可以用describe 看
[root@node-1 cm]# kubectl describe cm nginx-nc
Name:         nginx-nc
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
nginx_port:
----
80
nginx_server:
----
erick.com
Events:  <none>
[root@node-1 cm]# kubectl describe cm nginx-cm-from-file
Name:         nginx-cm-from-file
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
www.conf:
----
server {
  server_name myapp.com;
  port 80;
  root /data/web/html;

}

Events:  <none>

このようにして作成され、ファイルの内容への鍵、ファイル名のキーを見ることができます。

ポッドの関連付けを作成すると、作成したCM
[ルートノード-1センチ@]#猫のCM-1.yml
apiVersion:v1の
種類:ポッド
メタデータ:
名前:myappの-CM-1
の名前空間:デフォルト
注釈:
エリック: "によるエリック"
スペック:
コンテナ:

  • 名前:myappの-CM-1
    の画像:ikubernetes / myappの:v1の
    ポート:
    • 名前:HTTP
      containerPort:80
      ENV:
    • 名前:nginx_port
      valueFromおよび:
      configMapKeyRef:
      名前:nginxの-NC
      キー:nginx_port
    • 名前:nginx_server
      valueFromおよび:
      configMapKeyRef:
      名前:nginxの-NC
      キー:nginx_server

[ルート@ノード-1 cm]で#

コンテナや環境変数に参照してください
[ルートノード。1センチ&LT @] GET#kubectl POD
AGEのNAMEが再起動STATUS READY
MyAppのランニングに1/1。1 0センチ&LT 2m16s
[ルートノード。1センチ&LT @]#は、ExecがITを-cmの迅速化&LTのMyApp kubectl -1 - / binに/ SH
/#envを| grepをnginx_port
nginx_port = 80
/#envを| grepをnginx_server
nginx_server = erick.com
/#

私たちは、修正するために、環境変数のCM

[root@node-1 cm]# kubectl edit  configmap  nginx-nc
# 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: v1
data:
  nginx_port: "8080"
  nginx_server: erick.com
kind: ConfigMap
metadata:
  creationTimestamp: "2019-06-20T22:34:44Z"
  name: nginx-nc
  namespace: default
  resourceVersion: "436267"
  selfLink: /api/v1/namespaces/default/configmaps/nginx-nc
  uid: 9a180b6e-93ab-11e9-b0ae-080027edb92f
~                                          
把port修改成8080

再次查看环境变量是否更改
[root@node-1 cm]# kubectl exec -it myapp-cm-1 -- /bin/sh
/ # env|grep nginx_port
nginx_port=80
/ # 

結論:最初に作成したときのポッドの環境変数は、ポストの変更は有効になりません、それは効果の再起動ポッドを取らない場合でも、有効になります。

2。ポッドストレージ・ボリュームに基づいて、基準環境変数。

apiVersion:v1の
種類:ポッドの
メタデータ:
名前:myappcmwww
名前空間:デフォルト
の注釈:
エリック:「エリックによる」
スペック:
コンテナ:

  • 名前:myappcmwww
    画像:ikubernetes / myappの:v1の
    ポート:
    • 名前:HTTP
      containerPort:80
      volumeMounts:
    • 名前:nginxの-confに
      MOUNTPATH:/etc/nginx/conf.d/
      ボリューム:
  • 名前:nginxの-confに
    configMap:
    名前:nginxの-CM-からファイル
    [ルート@ノード-1センチ]#

環境変数にコンテナを参照してください
迅速化#のkubectl ExecのIT myappcmwww [ルートノードの1センチメートル&LT @。] - / binに/ SH
/ CAT#/etc/nginx/conf.d/
..2019_06_22_09_11_04.278015527 / ..data / www.conf
/ CAT番号の/etc/nginx/conf.d/www.confの
サーバー{
サーバー名myapp.com;
80を聞く;
ルート/データ/ウェブ/ HTML;

}
/#

configmapポート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: v1
data:
  www.conf: "server {\n\tserver_name myapp.com;\n\tlisten 8080;\n\troot /data/web/html;\n\n}\n"
kind: ConfigMap
metadata:
  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

在容器内查看环境变量是否更改。
/ # cat /etc/nginx/conf.d/www.conf 
server {
        server_name myapp.com;
        listen 8080;
        root /data/web/html;

}
/ # 

ダイナミックに変更されました。

シークレット
シークレット形式は、BASE64でエンコードされました

[root@node-1 cm]# kubectl create secret --help
[root@node-1 cm]# kubectl create secret --help
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 ## 放入证书时

Usage:
  kubectl create secret [flags] [options]

Use "kubectl <command> --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]# 

暗号化されてbash64を分泌する、復号化を逆にしてもよいです。

おすすめ

転載: blog.51cto.com/shyln/2415948