Search code examples
dockerkuberneteslagom

lagom configuration override


Is there any way to deploy lagom projects on kubernetes in different environments (ie. dev,stage,prod) such that I can use one image with multiple configuration overrides?

For example, let's say I have an environment variable, foo=bar-{{env}}. I want to build and publish one image and override configurations so that in dev foo=bar-dev and in prod foo=bar-prod.

Currently, my understanding is that the application.conf is tied to the image and cannot be overridden. If this is correct, is there a way to work around this so that I do not need to create multiple images, one for each environment?


Solution

  • You can do this in a few ways:

    Static:

    You can create 3 deployments in 3 namespaces and add the env variable to each deployment. You can manage these variables manually for each deployment:

    apiVersion: v1
    kind: Pod
    metadata:
      namespace: dev
      name: envar-demo
      labels:
        purpose: demonstrate-envars
    spec:
      containers:
      - name: java-demo-container
        image: my-super-java-app
        env:
        - name: foo
          value: "bar-dev"
        - name: JAVA_HOME
          value: "/opt/java/jdk1.7.0_05/bin/java"
    

    Helm:

    You can make helm chart and use 3 files with variables to deploy your application. To develop charts, you could read the official documentation or find some examples in official Kubernetes repo