Application Config file using Kubernetes ConfigMaps

10/12/2018

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 i.e. 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.

-- Umer
docker
kubernetes
vmware

1 Answer

10/13/2018

You can either create a ConfigMap or a Secret e.g.

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
-- Atul Verma
Source: StackOverflow