Getting Started with Helm Charts: A Beginner's Guide for Deploying Spring Boot Applications
1. Introduction to Helm
When working with Kubernetes, managing all the YAML files (Deployments, Services, ConfigMaps, etc.) can become complex and error-prone, especially as applications grow.
Helm is the package manager for Kubernetes, like Maven for Java. It simplifies deploying, versioning, and rolling back Kubernetes applications by packaging all necessary resources into a Chart.
Helm = Package Manager
Chart = A packaged application (like a
.jar
file for Java)
Think of a Helm Chart as a ready-to-install "Kubernetes application".
2. What is a Helm Chart?
A Helm Chart is a collection of files that describe a related set of Kubernetes resources.
Definition:
"A Helm Chart is a pre-configured Kubernetes resource bundle that can be installed, upgraded, or deleted as a single unit."
Use cases:
Deploy Spring Boot microservices easily.
Manage multiple environments (Dev, QA, Prod) with different configuration values.
Enable versioned and repeatable deployments.
3. Helm Chart Hub (Artifact Hub)
You don't always have to build charts from scratch.
Artifact Hub (https://artifacthub.io/ ) is a central repository where developers share public Helm Charts.
You can search for databases (PostgreSQL, MySQL), monitoring tools (Prometheus, Grafana), or example applications.
It's similar to Maven Central for Java libraries.
Example:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-mysql bitnami/mysql
4. Helm Chart vs Docker: Understanding the Difference
Many beginners confuse Docker and Helm. Here's a simple analogy:
Aspect | Docker | Helm |
---|---|---|
Purpose | Packages application code + dependencies into containers | Packages Kubernetes resource configurations into deployable units |
Output | Container Image (e.g., my-app:1.0 )
|
Helm Chart (e.g., my-springboot-app-0.1.0.tgz )
|
Usage | Run containers anywhere (Docker, Kubernetes, local VMs) | Deploy and manage Kubernetes resources easily |
Example | docker run my-app |
helm install my-app ./my-springboot-app |
Summary:
Docker focuses on packaging and running applications.
Helm focuses on packaging and deploying Kubernetes infrastructure (which runs Docker containers internally).
You usually need both for a full Kubernetes application:
Build a Docker image of your Spring Boot App.
Deploy it to Kubernetes using a Helm Chart.
5. Helm Chart Structure
When you create a Helm chart for your Spring Boot Web Application, the folder structure looks like this:
my-springboot-app/
├── Chart.yaml
├── values.yaml
├── templates/
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml (Optional)
│ ├── configmap.yaml (Optional)
│ ├── hpa.yaml (Optional)
├── charts/ (Optional - for dependencies)
└── templates/_helpers.tpl (Optional - for helper templates)
Let's understand each file:
a) Chart.yaml
Metadata about the chart (name, version, description).
Example:
apiVersion: v2
name: my-springboot-app
description: A Helm chart for deploying a Spring Boot Web Application
version: 0.1.0
appVersion: 1.0.0
b) values.yaml
The default configuration values.
You override these during deployment (
helm install -f custom-values.yaml
).Example:
replicaCount: 2
image:
repository: myregistry/my-springboot-app
tag: latest
service:
type: ClusterIP
port: 8080
c) templates/deployment.yaml
Defines the Kubernetes Deployment.
Uses placeholders like
{{ .Values.image.repository }}
to fetch values dynamically.Example snippet:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
spec:
containers:
- name: {{ .Release.Name }}
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
ports:
- containerPort: 8080
d) templates/service.yaml
Defines the Kubernetes Service (how your application is exposed internally).
Example snippet:
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: 8080
selector:
app: {{ .Release.Name }}
e) templates/ingress.yaml (Optional)
Used if you want to expose your service externally with a domain name.
f) templates/configmap.yaml (Optional)
Inject environment-specific configs without rebuilding images.
g) templates/hpa.yaml (Optional)
For Horizontal Pod Autoscaling (auto-scaling pods based on CPU/memory).
6. Create Your First Helm Chart for Spring Boot
Steps:
Install Helm CLI:
brew install helm # MacOS
choco install kubernetes-helm # Windows
Scaffold a new Chart:
helm create my-springboot-app
Update templates and values.yaml to match your application.
Package and Deploy:
helm install my-app ./my-springboot-app
To upgrade after changes:
helm upgrade my-app ./my-springboot-app
7. Real-World Example: Deploying a Spring Boot Web App
Suppose you have a Spring Boot app exposing /api/hello
on port 8080. Here’s a minimal values.yaml:
image:
repository: myregistry/my-springboot-app
tag: 1.0.0
service:
type: LoadBalancer
port: 8080
replicaCount: 3
After helm install
, your app is available via the LoadBalancer IP.
8. Summary
Component | Purpose |
Chart.yaml | Metadata about the application |
values.yaml | Default configurations |
templates/*.yaml | Kubernetes resource definitions |
Comments
Post a Comment