If there is a Java argument issue with Kubernetes deployment...

If there is a Java argument issue with Kubernetes deployment...
Kubernetes Image from Ihor Dvoretskyi (Unsplash)

Maybe this issue is "NOT" always happening to all Java spring boot application running on Kubernetes.

However, if YAML file is being used to create Kubernetes pods and for some reason, java arguments' values in deployment yaml file can not be retrieved from the application during/after deployment. This post might help you.

Here is the example of deployment.yaml

aviVersion: apps/v1
kind: Deployment
metadata:
...
...
template:
	spec:
    ...
    containers:
    - name: my-app
      image: docker.image.io/projects/my-app:12d4x3490df329dkkk5bb2v6e9e
      workingDir: /projects/my-app
      command:
      - java
      args:
      	- -jar
        - /projects/my-app/app.jar
        - -Dlogging.config="/projects/my-app/log4j2.xml"
        - -DdbHost="$(DB_HOST)"
        - -DdbUsername="$(DB_USERNAME)"
        - -DdbPassword="$(DB_PASSWORD)"
        ...
        ...

Let's assume the following arguments are originally retrieved from either application.properties or application.yaml file.

  • dbHost
  • dbUsername
  • dbPassword

From most of cases, these properties values will be different based on your environment such as Test, UAT or Prod.  In your Kubernetes setup, they are highly likely to be encoded and placed in each env's secret file.

If you can see that

  • property values are not getting picked up according to your value in the secret.
  • property values are identical through all environment (They are supposed to be different)

, then check if your arguments' names are matching with the corresponding the key name in its secrets files. In other words, make sure your corresponding key name in the secret.yaml file was being set correctly.

For example of these arguments, they can change as follows:

  • dbHost -> db.host since DB_USERNAME is the key name
  • dbUsername -> db.username since DB_USERNAME is the key name
  • dbPassword -> db.password since DB_PASSWORD is the key name

Basically,  when you create the corresponding key-value pair data in the secret files, do

  • Change the value name to Upper Case (E.g., db.host -> DB.HOST)
  • Replace "." to "_" if needed (E.g. DB.HOST -> DB_HOST)

This should be able to resolve the issue.

Hope this is helpful. Happy Coding!