3

NOT WORKING SCENARIO:

I am trying to deploy spring-boot application in EKS cluster.

spring-config-server helps to load myapplication(project) properties from repository

  • myapplication-dev.yml (From repository)
spring: 
  config: 
    import: optional:configtree:/usr/src/apps/secrets/database/postgresql/ # not effective while loading into application by configserver
  datasource: 
    url: jdbc:postgresql://{xxxxxxxxxxxxxx}:{5444}/postgres
    username: ${DB_USERNAME}
    password: ${DB_PASSWORD}
    hikari: 
      schema: mydbschema

spring-config-server is up and running! When i am trying to deploy myapplication with deployment.yaml file in EKS then configtree:/usr/src/apps/secrets/database/postgresql/ property not showing any effect in order to set env props.

  • deployment.yaml
      volumes: 
      - name: tmpfs-1
        emptyDir: {}
      - name: secret-volume-postgresql
        secret:
          secretName: db_secrets
      containers:
      - name: {{ .Chart.Name }}
        securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        args:
        - "--server.port=8080"
        - {{ default "dev" .Values.applicationActiveProfiles }}
        env:
        - name: ACTIVE_PROFILES
          value: {{ .Values.applicationActiveProfiles }}
        - name: DB_USERNAME
          value: {{ .Values.db.userName }}
        - name: NAME_SPACE
          value: {{ default "dev" .Values.selectedNamespace }}
        ports:
        - name: http
          containerPort: {{ .Values.containerPort }}
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /actuator/health/readiness
            port: http
            scheme: HTTP
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /actuator/health/liveness
            port: http
            scheme: HTTP
          initialDelaySeconds: 15
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        volumeMounts:
        - name: secret-volume-postgresql
          mountPath: /usr/src/apps/secrets/database/postgresql 
        - name: tmpfs-1
          mountPath: /tmp

  • myapplication(project)
    • application.yml
---
spring:
  application:
    name: myapplication
  config:
    import: optional:configserver:http://config-server.dev.svc:8080/
  cloud:
    config:
      label: develop
  profiles:
    active:
    - dev 

Working scenario:

With one additional change in deployment.yaml file, that setting up spring.config.import as arg.

      containers:
      - name: {{ .Chart.Name }}
        securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        args:
        - "--server.port=8080"
        - {{ default "dev" .Values.applicationActiveProfiles }}
        # ******It's working after adding the below line******
        - "--spring.config.import=optional:configtree:/usr/src/apps/secrets/database/postgresql/"

Question: Why it's not considering the property that i set in myapplication-dev.yml file ? What is missing here ?

Prashant
  • 616
  • 6
  • 10
  • What is the configuration of the Spring Cloud Config Server itself? Is it available at `http://config-server.dev.svc:8080` after being deployed? Can you curl it to check the retrieval of the `myapplication` config? Why are you using `optional:` in `import: optional:configserver:http://config-server.dev.svc:8080/` if that is your primary configuration source? – dekkard Jan 05 '23 at 17:18

0 Answers0