Dynamic Configuration with Helm Charts and Spring Boot

Ashok Gudise
4 min readSep 14, 2023

--

In the context of modern cloud-based containerized applications, the ability to adapt and customize application behavior dynamically is more critical than ever.

Imagine scenarios where you need to change a client’s name within your application without deploying a new version, or fine-tune your application’s behavior on-the-fly. These use cases highlight the importance of dynamic configuration management, a cornerstone of modern software development practices.

Prerequisites

Before diving into the setup, ensure you have the following prerequisites:

  • Kubernetes Cluster configured and Helm Installed

You can perform the installation by adhering to the guidelines provided in my alternative instructions.

  • You can install helm charts by following steps mentioned in this url

Step 1: Create a Spring Boot App

This is a standard Spring Boot application, and you can access the complete code here at GitHub. I’d like to emphasize the specific modifications relevant to the topic to this blog.

application-custom.yml

Observe that we’ve established placeholders within the application-custom.yml file, with the expectation that these placeholders will be populated upon application initialization. We will delve into the process of injecting these values from the values.yml file within our Helm charts, as detailed below.

#application-custom.yml

server:
port: 8080

app:
client-name: ${CLIENT_NAME}
welcome-message: ${WELCOME_MESSAGE}

Service

Controller

Step 2: Create Helm Charts

Navigate to the project root folder and type below mentioned command to create the folder and default files.

helm create custom-app-demo

Go to the files listed below and insert the provided code:

deployment.yml

      containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
env:
- name: SPRING_PROFILES_ACTIVE
value: {{ .Values.app.customizations.profile }}
- name: CLIENT_NAME
value: {{ .Values.app.customizations.client_name }}
- name: WELCOME_MESSAGE
value: {{ .Values.app.customizations.welcome_message }}

values.yml

We’re specifying the Spring profile value as “custom” to enable dynamic configuration.

app:
customizations:
profile: custom
client_name: My-Coffee-Brand
welcome_message: Welcome to the customized app from K8s

Step 3: Deploy your code

Execute the Helm chart installation to deploy this code within your local cluster.

helm install --debug custom-app-demo ./deployment/custom-app-demo/

Step 4: Now, Let’s test the App in browser

Big Picture

IMPORTANT: It’s important to note that while the approach we’re demonstrating here is a powerful way to implement dynamic configuration, it may not be suitable for handling sensitive information such as passwords and confidential data. Storing such data in ConfigMaps or Secrets, as shown in this blog post, can pose security risks.

For securing sensitive information, I strongly recommend using a vault-based approach or some other secured approach, where secrets are stored securely in a centralized vault system and accessed by your applications through well-defined authentication and authorization mechanisms. Although this blog doesn’t cover vault-based solutions, it’s crucial to prioritize security and choose the appropriate method based on your specific application’s requirements and security considerations.

To provide you with a holistic understanding of how to set up configurations when dealing with sensitive data in the architecture diagram below.

Summary

In conclusion, this blog has explored the dynamic configuration management of Spring Boot applications using Helm charts within a containerized environment. By adhering to the principles of the 12-factor app methodology, we have demonstrated how to achieve flexibility and adaptability in your applications, allowing for dynamic changes to application behavior and settings without the need for extensive redeployment.

While this approach offers significant advantages in terms of maintainability and scalability, it’s important to exercise caution when dealing with sensitive information. For secure handling of confidential data such as passwords, we recommend a vault-based approach, which ensures a higher level of security.

By embracing dynamic configuration and containerization, you can create applications that are better suited to the dynamic demands of today’s software landscape, ultimately enhancing your development and deployment workflows.

If you found my blog posts enjoyable and gained new insights, I kindly ask you to think about sharing them and joining me here for future updates. You can find the source code on my GitHub. You can reach out to me on LinkedIn for any questions or suggestions.

That’s all for now, Happy Learning!

--

--

Ashok Gudise

I am an enthusiastic learner who is curious to learn new market trends and new technologies that make software engineering much more robust and easy to learn.