Helm Charts for Spring Boot: Templating, Values & Rollbacks
Helm is the package manager for Kubernetes. Instead of maintaining separate YAML files per environment, you write templates with placeholder values and override them per deployment. A Helm release tracks every install and upgrade, making rollbacks a one-command operation. This article walks through creating a production-quality Helm chart for a Spring Boot service, customising it per environment, and managing the release lifecycle.
Contents
What Helm adds to plain manifests Chart structure Chart.yaml: the chart's metadata values.yaml: the defaults The ConfigMap and Deployment templates _helpers.tpl: named templates Environment-specific overrides Install, upgrade and rollback Database migrations with Helm hooks Helmfile: several services together Helm in a CI pipeline Best practices
What Helm adds to plain manifests
Plain Kubernetes manifests are fixed text. Running the same service in staging and production means two copies of every file that differ in a handful of values, such as the replica count, the host name or the memory limit. Over time the copies drift apart in ways nobody intended.
Helm separates the two. A chart holds templates, which are manifests with placeholders, and a values.yaml
Each installed copy of a chart is a release, and every install, upgrade or rollback of it is a numbered revision. Helm 3 and later store each revision as a Secret in the release's namespace, which is how helm historyhelm rollback
Values come from three places, and later ones win:
| Source | Typical use |
|---|---|
The chart's values.yaml | Defaults that suit every environment |
Files passed with -f--values | One file per environment, such as values-production.yaml |
--set key=value | A value known only at deploy time, such as the image tag from CI |
The rest of this page builds a chart for a Spring Boot service, then shows how to release it, run database migrations as part of a release, and manage several services together.
Chart structure
A chart is a folder with a fixed layout. helm create
payment-service/ ← chart name
├── Chart.yaml ← chart metadata (name, version, appVersion)
├── values.yaml ← default values
├── values-staging.yaml ← staging overrides
├── values-production.yaml ← production overrides
└── templates/
├── _helpers.tpl ← reusable named templates
├── deployment.yaml
├── service.yaml
├── ingress.yaml
├── configmap.yaml
├── hpa.yaml
├── serviceaccount.yaml
├── db-migrate-job.yaml ← database migration, run by a hook
└── NOTES.txt ← printed after install
# Create scaffold with helm create
helm create payment-service
Chart.yaml: the chart's metadata
Chart.yamlversionappVersion
# Chart.yaml
apiVersion: v2
name: payment-service
description: Spring Boot payment microservice
type: application
version: 0.1.0 # chart version: increment on chart changes
appVersion: "1.0.0" # application version: the Docker image tag
maintainers:
- name: platform-team
email: platform@example.com
values.yaml: the defaults
values.yaml
# values.yaml
replicaCount: 2
image:
repository: myorg/payment-service
tag: "" # defaults to Chart.appVersion if empty
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
targetPort: 8080
ingress:
enabled: false
className: nginx
host: payment.example.com
tls: true
resources:
requests:
cpu: 250m
memory: 1Gi
limits:
memory: 1Gi
autoscaling:
enabled: false
minReplicas: 2
maxReplicas: 10
targetCPUUtilizationPercentage: 70
springProfiles: "production"
database:
url: "jdbc:postgresql://postgres.payments.svc:5432/payments"
config: # becomes the ConfigMap shown below
logLevel: INFO
maxRetryAttempts: 3
podAnnotations: {}
nodeSelector: {}
tolerations: []
affinity: {}
The ConfigMap and Deployment templates
Templates are Kubernetes manifests with placeholders. {{ .Values.x }}include_helpers.tplnindentconfig
{{/* templates/configmap.yaml */}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "payment-service.fullname" . }}-config
labels:
{{- include "payment-service.labels" . | nindent 4 }}
data:
LOGGING_LEVEL_ROOT: {{ .Values.config.logLevel | quote }}
APP_RETRY_MAX_ATTEMPTS: {{ .Values.config.maxRetryAttempts | quote }}
Then the Deployment:
{{/* templates/deployment.yaml */}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "payment-service.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "payment-service.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "payment-service.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "payment-service.selectorLabels" . | nindent 8 }}
annotations:
# Force pod restart when ConfigMap changes (checksum annotation)
checksum/config: >-
{{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
containers:
- name: {{ .Chart.Name }}
image: >-
{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 8080
env:
- name: SPRING_PROFILES_ACTIVE
value: {{ .Values.springProfiles | quote }}
- name: JAVA_TOOL_OPTIONS
value: "-XX:MaxRAMPercentage=75.0"
envFrom:
- configMapRef:
name: {{ include "payment-service.fullname" . }}-config
resources:
{{- toYaml .Values.resources | nindent 12 }}
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8080
initialDelaySeconds: 20
periodSeconds: 10
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
initialDelaySeconds: 30
periodSeconds: 15
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
The checksum/config>-
_helpers.tpl: named templates
Files starting with an underscore are not rendered as manifests. They hold named templates that the other files reuse, so names and labels are defined once:
{{/* templates/_helpers.tpl */}}
{{/* Full name: release-name + chart-name, capped at 63 chars */}}
{{- define "payment-service.fullname" -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/* Common labels */}}
{{- define "payment-service.labels" -}}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
{{ include "payment-service.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/* Selector labels */}}
{{- define "payment-service.selectorLabels" -}}
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Environment-specific overrides
An environment's values file contains only what differs from values.yaml
# values-production.yaml: overrides on top of values.yaml defaults
image:
tag: "1.2.3" # pin exact version in production
ingress:
enabled: true
host: api.example.com
autoscaling:
enabled: true # the autoscaler sets the replica count, so replicaCount is ignored
minReplicas: 3
maxReplicas: 20
resources:
requests:
cpu: 500m
memory: 2Gi
limits:
memory: 2Gi
config:
logLevel: WARN
Install, upgrade and rollback
Every installupgrade
# Lint: validate templates before deploying
helm lint ./payment-service -f payment-service/values-production.yaml
# Dry-run: render templates without applying
helm install payment-service ./payment-service \
--namespace payments \
--values payment-service/values-production.yaml \
--dry-run --debug
# Install
helm install payment-service ./payment-service \
--namespace payments --create-namespace \
--values payment-service/values-production.yaml
# Upgrade: deploy new image version
helm upgrade payment-service ./payment-service \
--namespace payments \
--values payment-service/values-production.yaml \
--set image.tag=1.3.0 \
--rollback-on-failure \
--timeout 5m
# --rollback-on-failure waits until the new pods are ready, and rolls back
# by itself if they are not ready within --timeout (Helm 3 calls it --atomic)
# View release history
helm history payment-service -n payments
# Rollback to previous revision
helm rollback payment-service -n payments
# Rollback to specific revision
helm rollback payment-service 2 -n payments
# Uninstall
helm uninstall payment-service -n payments
Database migrations with Helm hooks
A hook is a resource Helm creates at a fixed point in a release instead of with the rest, for example a Job that migrates the database before new pods start. The example runs Flyway from an image that contains only the migration scripts:
# Dockerfile.migrations: the Flyway CLI plus this service's SQL scripts
FROM flyway/flyway:11
COPY src/main/resources/db/migration /flyway/sql
{{/* templates/db-migrate-job.yaml */}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "payment-service.fullname" . }}-db-migrate
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
backoffLimit: 1
template:
spec:
restartPolicy: Never
containers:
- name: migrate
image: >-
myorg/payment-service-migrations:{{ .Values.image.tag | default .Chart.AppVersion }}
args: ["migrate"]
env:
- name: FLYWAY_URL
value: {{ .Values.database.url | quote }}
- name: FLYWAY_USER
valueFrom:
secretKeyRef: { name: payment-service-db, key: username }
- name: FLYWAY_PASSWORD
valueFrom:
secretKeyRef: { name: payment-service-db, key: password }
If the Job fails, Helm stops the upgrade and the running version stays in place. Two things to know:
- Hooks run before the chart's own resources exist: On a first install, a Secret or ConfigMap that the chart creates is not there yet when a
hook runs. That is why the database Secret here is created outside the chart. Alternatively, make the Secret a hook too, with a lowerpre-install , so it is created first.hook-weight - Old and new pods share the database during a rollout: The migration runs before the new pods start, while the old ones still serve traffic, so each migration must keep working with the previous version of the code.
If you do not need a separate step, Spring Boot runs Flyway itself at startup when flyway-core
The
Helmfile: several services together
Helmfile declaratively manages multiple Helm releases: useful for deploying a full microservices stack with one command. The file below uses a template expression, {{ .Environment.Name }}helmfile.yaml.gotmpl
# helmfile.yaml.gotmpl
releases:
- name: payment-service
namespace: payments
chart: ./charts/payment-service
values:
- ./values/payment-service/values-{{ .Environment.Name }}.yaml
- name: order-service
namespace: orders
chart: ./charts/order-service
values:
- ./values/order-service/values-{{ .Environment.Name }}.yaml
environments:
staging: {}
production: {}
Charts from a repository are added the same way, with a repositorieschart: repo-name/chart-nameversion
# Deploy all services to staging
helmfile -e staging apply
# Diff before applying to production
helmfile -e production diff
# Apply to production
helmfile -e production apply
Helm in a CI pipeline
In a pipeline, the same commands run without a person watching, so each step has to catch its own mistakes. Three steps cover most of it: lint the chart, render it to check what will be applied, then install or upgrade with an automatic rollback:
# 1. Catch template and YAML mistakes before anything reaches a cluster
helm lint ./payment-service -f payment-service/values-production.yaml
# 2. Render the manifests locally, to review or validate them
helm template payment-service ./payment-service \
-f payment-service/values-production.yaml \
--set image.tag="$GIT_COMMIT" > rendered.yaml
# 3. Install or upgrade in one idempotent command
helm upgrade --install payment-service ./payment-service \
--namespace payments \
-f payment-service/values-production.yaml \
--set image.tag="$GIT_COMMIT" \
--rollback-on-failure --timeout 5m
needs no cluster. The rendered file can be reviewed in a pull request, or checked against the Kubernetes schemas with a validator such as kubeconform, so a misspelled field fails the build instead of the deployment.helm template installs the release the first time and upgrades it afterwards, so the pipeline needs no special case for a new environment.upgrade --install- The image tag is the commit id, passed with
, so every revision in--set points to an exact build. Seehelm historybuilding the JAR in CI for the image side. - Helm 4, released in November 2025, renamed
to--atomic ; the old name still works with a warning. Helm 3 receives security fixes until February 2027.--rollback-on-failure
Best practices
- Keep one chart per service, with defaults in
and only the differences in each environment's file.values.yaml - Raise the chart
on every template change, and set the image tag per deployment rather than editingversion by hand.appVersion - Never put secrets in values files that are committed to Git. Reference Secrets created outside the chart, for example by the External Secrets Operator: see
ConfigMaps and Secrets . - Add the
annotation, so configuration changes roll out new pods.checksum/config - Release with
and a timeout, so a release whose pods never become ready undoes itself.--rollback-on-failure - Keep database migrations backward compatible, because old pods keep running while the hook migrates.
- Render and validate templates in CI before every release.
- Pin the versions of charts you depend on, in
dependencies or Helmfile, so upgrades happen when you choose.Chart.yaml
For the Kubernetes settings the chart's templates contain, see