简体   繁体   中英

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.

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.

{
  "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.

My DockerFile for this project consists of copying two separate/dependent projects, setting ENV, NPM Installs and exposing PORTS.

PS - the Docker Image is pushed to my Private Repository.

Experts advise would be highly appreciated.

You can either create a ConfigMap or a Secret eg

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

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.

volumeMounts:
    - name: test-secretm
      mountPath: PATH_OF_YOUR_CONFIG_JSON

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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