ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

|NO.Z.00171|——————————|CloudNative|——|KuberNetes&配置管理.V02|------------------------------------------

2022-03-30 13:33:49  阅读:231  来源: 互联网

标签:configmap env 文件创建 配置管理 game ui file k8s




[CloudNative:KuberNetes&配置管理.V02]                                                               [Applications.KuberNetes][|DevOps|k8s|配置管理|k8s配置管理ConfigMap|]








一、从文件创建configmap
### --- 可以用来kubectl create configmap从单个文件或多个文件创建ConfigMap。
~~~     也可以定义它的名字,在前面加入命名方式,若是不加的话默认是按照它的文件名来命名的:
~~~     这种方式在生产环境中是最常用的。

[root@k8s-master01 ~]# kubectl create cm game-ui-cm --from-file=configure-pod-container/configmap/ui.properties 
configmap/game-ui-cm created
[root@k8s-master01 ~]# kubectl describe cm game-ui-cm
Name:         game-ui-cm
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
ui.properties:                  // 这次创建的只有ui.properties
----
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
二、使用--from-file参多次传入参数
### --- 可以--from-file多次传入参数以从多个数据源创建ConfigMap。

[root@k8s-master01 ~]# kubectl create cm game-ui-cm-custom-name --from-file=ui-pro=configure-pod-container/configmap/ui.properties 
configmap/game-ui-cm-custom-name created
[root@k8s-master01 ~]# kubectl describe cm game-ui-cm-custom-name
Name:         game-ui-cm-custom-name
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
ui-pro:                             // 可以看到它的名称发生了变化,是我们定义的参数。
----
color.good=purple
color.bad=yellow
allow.textmode=true
how.nice.to.look=fairlyNice
三、使用该选项--from-env-file可从环境文件创建configmap
### --- from-env-file也是一个kv形式的,它创建的不包含名字;直接读出下面的参数

[root@k8s-master01 comfigmap]# cat configure-pod-container/configmap/game.properties 
enemies=aliens
lives=3
allowed="true"
[root@k8s-master01 configmap]# wget https://kubernetes.io/examples/configmap/game-env-file.properties -O configure-pod-container/configmap/game-env-file.properties
### --- 创建env

[root@k8s-master01 configmap]# kubectl create configmap game-config-env-file --from-env-file=configure-pod-container/configmap/game-env-file.properties 
configmap/game-config-env-file created
四、查看game-config-env-file.yaml
### --- 查看创建的configmap.yaml配置文件
~~~     警告:--from-env-file多次传递以从多个数据源创建ConfigMap时,仅使用最后一个env文件。

[root@k8s-master01 configmap]# kubectl get configmap game-config-env-file -o yaml
apiVersion: v1
data:
  allowed: '"true"'
  enemies: aliens
  lives: "3"
kind: ConfigMap
metadata:
  creationTimestamp: "2021-04-24T10:07:54Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:data:
        .: {}
        f:allowed: {}
        f:enemies: {}
        f:lives: {}
    manager: kubectl-create
    operation: Update
    time: "2021-04-24T10:07:54Z"
  name: game-config-env-file
  namespace: default
  resourceVersion: "640922"
  uid: fad61760-e146-476d-ac6b-7db98c6cbc12
五、然后通过env文件生成环境变量
### --- 然后通过env文件生成环境变量:--from-env-file多次通过的行为通过以下方式证明:

[root@k8s-master01 ~]# wget https://kubernetes.io/examples/configmap/ui-env-file.properties -O configure-pod-container/configmap/ui-env-file.properties
### --- 创建2个这个文件

[root@k8s-master01 configmap]# kubectl create configmap config-multi-env-files \
>         --from-env-file=configure-pod-container/configmap/game-env-file.properties \
>         --from-env-file=configure-pod-container/configmap/ui-env-file.properties
configmap/config-multi-env-files created
六、查看创建的config-multi-env-files配置文件
### --- 查看创建的yaml配置文件

[root@k8s-master01 comfigmap]# kubectl get configmap config-multi-env-files -o yaml
apiVersion: v1
data:
  color: purple
  how: fairlyNice
  textmode: "true"
kind: ConfigMap
metadata:
  creationTimestamp: "2021-04-24T10:10:59Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:data:
        .: {}
        f:color: {}
        f:how: {}
        f:textmode: {}
    manager: kubectl-create
    operation: Update
    time: "2021-04-24T10:10:59Z"
  name: config-multi-env-files
  namespace: default
  resourceVersion: "641356"
  uid: aacb394c-23c4-48f1-af7e-e2465f204426








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                   ——W.S.Landor



来自为知笔记(Wiz)

标签:configmap,env,文件创建,配置管理,game,ui,file,k8s
来源: https://www.cnblogs.com/yanqivip/p/16076571.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有