简体   繁体   English

使用Kubernetes ConfigMaps的应用程序配置文件

[英]Application Config file using Kubernetes ConfigMaps

I would like to ask, what is the preferred way or best way to pass Config file for my app under the following scenario. 我想问一下,在以下场景下,为我的应用程序传递Config文件的首选方式或最佳方式是什么。

My app is developed on NodeJS and i have a JSON file called "config.json" that contains all the config parameters of my application ie AD, SMTP, DB etc. a glimpse of the file is like. 我的应用程序是在NodeJS上开发的,我有一个名为“config.json”的JSON文件,其中包含我的应用程序的所有配置参数,即AD,SMTP,DB等。文件的一瞥就像。

{
  "slackIncomingHook": [
    {"HookUrl": "<<HookUrl>>"}
  ],
  "wikiPage": {
    "url": "<<url>>",
    "timeFrame" : "week"
  },
  "database": {
    "dbName": "DBNAME",
    "dbHostName": "mongodb://username:password@<<IP Address>>:27017/"
  }
}

Now i want to deploy this project using Kubernetes and i want to pass this information to at runtime or somehow merged at the time when the cluster is being built using configMaps. 现在我想使用Kubernetes部署这个项目,我想在运行时传递这些信息,或者在使用configMaps构建集群时以某种方式合并。

My DockerFile for this project consists of copying two separate/dependent projects, setting ENV, NPM Installs and exposing PORTS. 我的这个项目的DockerFile包括复制两个独立/依赖项目,设置ENV,NPM安装和暴露PORTS。

PS - the Docker Image is pushed to my Private Repository. PS - Docker Image被推送到我的私人存储库。

Experts advise would be highly appreciated. 专家建议将受到高度赞赏。

You can either create a ConfigMap or a Secret eg 你可以创建一个ConfigMap或一个秘密例如

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
  namespace: default
data:
  AppConfig.json: |-
    {
      "slackIncomingHook": [
        {"HookUrl": "<<HookUrl>>"}
      ],
      "wikiPage": {
        "url": "<<url>>",
        "timeFrame" : "week"
      },
      "database": {
        "dbName": "DBNAME",
        "dbHostName": "mongodb://username:password@<<IP Address>>:27017/"
      }
    }

You can create secret also as they are base64 encoded so 您也可以创建机密,因为它们是base64编码的

apiVersion: v1
kind: Secret
metadata:
  name: test-secret
  namespace: default
type: Opaque
data:
  AppConfig.json: |-
     BASE_64_ENCODED_JSON

In the deployment, add secret/config to volumes node and set volume mounts and mountPath to the path of your config.json. 在部署中,将secret / config添加到卷节点并将卷装入和mountPath设置为config.json的路径。

volumeMounts:
    - name: test-secretm
      mountPath: PATH_OF_YOUR_CONFIG_JSON

volumes:
      - name: test-secretm
        secret:
            secretName: test-secret

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM