Micronaut Application on Kubernetes not able to pick up a property from yml

125 views Asked by At

Running a micronaut application on kubernetes where configs are loaded from configMap.

Firstly, my configmap.yml looks like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: data-loader-service-config
data:
  application-devcloud.yml: |-
    data.uploaded.event.queue: local-datauploaded-event-queue
    data.uploaded.event.consumer.concurrency: 1-3
    base.dir: basedir
    aws:
      region: XXX
      
    datasources:
      default:
        dialect: POSTGRES
        driverClassName: org.postgresql.Driver
    micronaut:
      config:
        sources:
          - file:/data-loader-service-config
        debug: true
      jms:
        sqs:
          enabled: true

My deployment yml looks like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    app.dekorate.io/vcs-url: <<unknown>>
    app.dekorate.io/commit-id: c041d22bc8a1a69a4c9016b77d9df465c8ca9d83
  labels:
    app.kubernetes.io/name: data-loader-service
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: data-loader-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: data-loader-service
      app.kubernetes.io/version: 0.1-SNAPSHOT
  template:
    metadata:
      annotations:
        app.dekorate.io/vcs-url: <<unknown>>
        app.dekorate.io/commit-id: c041d22bc8a1a69a4c9016b77d9df465c8ca9d83
      labels:
        app.kubernetes.io/name: data-loader-service
        app.kubernetes.io/version: 0.1-SNAPSHOT
    spec:
      containers:
        - env:
            - name: KUBERNETES_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: MICRONAUT_ENVIRONMENTS
              value: "devcloud"
            - name: aws.region
              value: xxx
          image: mynamespace/data-loader-service:0.1-SNAPSHOT
          imagePullPolicy: Always
          name: data-loader-service
          volumeMounts:
            - name: data-loader-service-config
              mountPath: /data-loader-service-config
      volumes:
        - configMap:
            defaultMode: 384
            name: data-loader-service-config
            optional: false
          name: data-loader-service-config

When my micronaut app in the pod starts up, it is not able to resolve base.dir.

Not sure what's missing here.

1

There are 1 answers

0
user1189332 On

Here is what I ended up doing. It works. I don't think it's the cleanest way though.

---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    app.dekorate.io/vcs-url: <<unknown>>
    app.dekorate.io/commit-id: c041d22bc8a1a69a4c9016b77d9df465c8ca9d83
  labels:
    app.kubernetes.io/name: data-loader-service
    app.kubernetes.io/version: 0.1-SNAPSHOT
  name: data-loader-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: data-loader-service
      app.kubernetes.io/version: 0.1-SNAPSHOT
  template:
    metadata:
      annotations:
        app.dekorate.io/vcs-url: <<unknown>>
        app.dekorate.io/commit-id: c041d22bc8a1a69a4c9016b77d9df465c8ca9d83
      labels:
        app.kubernetes.io/name: data-loader-service
        app.kubernetes.io/version: 0.1-SNAPSHOT
    spec:
      containers:
        - env:
            - name: KUBERNETES_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: MICRONAUT_ENVIRONMENTS
              value: "devcloud"
            - name: MICRONAUT_CONFIG_FILES
              value: "/config/application-common.yml,/config/application-devcloud.yml"
            - name: aws.region
              value: xxx
          image: xxx/data-loader-service:0.1-SNAPSHOT
          imagePullPolicy: Always
          name: data-loader-service
          volumeMounts:
            - name: data-loader-service-config
              mountPath: /config
      volumes:
        - configMap:
            defaultMode: 384
            name: data-loader-service-config
            optional: false
          name: data-loader-service-config