Deploying Grails apps to Kubernetes with Helm

Grails turns a Groovy codebase into a complete web application, yet shipping that application beyond a laptop is where many teams lose momentum. Containerising the compiled Grails app is only the first step; the second is describing how the workload should run, how it should scale, and how it should differ between environments. Helm charts provide that declarative layer: a versioned package of Kubernetes manifests, rendered from values files, that you can install, upgrade and roll back without editing raw YAML by hand.

This walkthrough takes a standard Grails application with Grails MVC controllers and a Gradle build, packages it into a container image, wraps the deployment objects in a chart, and then moves that chart through a CI pipeline into a managed Kubernetes cluster. You will need a JDK 17 or 21 toolchain, the Grails command line, Docker or Podman, kubectl, Helm 3, and either a local kind or minikube cluster or a managed offering such as EKS, AKS or GKE. Everything shown here also runs on a laptop, so you can rehearse the whole workflow before touching cloud infrastructure.

Package the Grails app as a container image

A Grails project compiles to a WAR file or a runnable JAR that embeds Tomcat, and production images should run that artefact rather than the Grails interactive command. The most reliable Dockerfile uses a multi-stage build: the first stage copies the Gradle wrapper and source, runs the wrapper to resolve dependencies and assemble the artefact, and the second stage copies only the resulting file into a slim JRE base image. Caching Gradle's dependency directory between builds keeps CI times short, and the build stage never reaches the runtime image, so compilers and source code stay out of production.

Runtime details matter more than they look. Containers have a cgroup memory limit, so leave the JVM to read that limit rather than hard-coding a heap size; settings such as MaxRAMPercentage and an explicit heap ceiling avoid an out-of-memory kill when Kubernetes enforces the limit you declared in your chart. Run the process as a non-root user, keep the image free of package managers and shells you do not need, and expose a single port. Add a small controller or health plugin that returns a simple 200 response so the kubelet has something to probe for liveness and readiness; a check that touches the database on every request can make a pod look healthy when its real dependency has already gone.

Tag images with the commit SHA rather than a floating tag, push them to a registry near your cluster — Amazon ECR in Sydney, Azure Container Registry in Australia East, or a private GitHub Packages repository all work — and pin the digest in your values file so a deployment stays reproducible even if somebody later overwrites the tag.

Lay out a chart that mirrors the Grails service

A chart is a small filesystem: Chart.yaml holding chart metadata, values.yaml holding defaults, a templates directory with one file per Kubernetes object, and an optional charts directory for dependencies. Start with templates for the Deployment, the Service and its load balancer or ClusterIP type, a ConfigMap for non-sensitive configuration, a ServiceAccount, and an Ingress or Gateway resource if you terminate TLS at the edge. Add a HorizontalPodAutoscaler, PodDisruptionBudget and NetworkPolicy later, as separate templates so each can be switched on from values.

Templates read from the rendering context, so use the chart's helper templates to generate consistent names and labels instead of repeating string concatenation in every file. The Deployment's selector must match the pod template labels exactly or the controller rejects the manifest. When configuration lives in a ConfigMap, include a checksum of that ConfigMap in the pod template annotations; Kubernetes then rolls the pods automatically when the configuration changes, which prevents the stale-config problem that plagues long-lived Grails deployments.

Before anything reaches a cluster, run helm lint and helm template against the chart and read the output. The rendered manifests are what Kubernetes actually receives, so reviewing them catches quoting mistakes, missing required values and indentation errors that a YAML parser alone will not. A dry-run install against a disposable namespace is a good final check.

Keep environment differences in values files

One chart should serve every environment, with the differences expressed as values rather than as forks of the template. Keep a small values.yaml with safe defaults, then maintain values-staging.yaml and values-production.yaml overlays that set replica counts, resource requests, JVM options, ingress hosts and image tags. Helm merges those files in order, so an overlay only needs to state what changes, and helm upgrade --install with the right --values flag becomes the single entry point for promoting a release:

helm upgrade --install grails-api ./charts/grails-api \
  --namespace grails --create-namespace \
  --values ./charts/grails-api/values-production.yaml \
  --atomic --wait --timeout 5m

Secrets deserve different treatment from configuration. Store them in Kubernetes Secrets created by a secrets manager, encrypt them at rest with a KMS key held in an Australian region, and reference them through environment variables or volume mounts rather than committing them to values files. Australian teams running customer-facing services increasingly keep their primary data in-country — AWS Sydney and Melbourne regions, Azure Australia East and Australia South — and a chart makes that constraint explicit, because region names, storage classes and endpoint URLs all become values that must match the data-residency policy signed off for fintech, logistics and health organisations in Sydney and Melbourne.

Automate chart releases in a pipeline

Manual helm upgrade commands work for a first experiment, but they leave no audit trail and no reliable rollback. A pipeline should build and push the image, run the test suite, package the chart with helm package, push it as an OCI artefact to a registry, and then deploy it. Before any artefact is published, gate the build on coverage; the guide to Grails and JaCoCo coverage shows how to wire JaCoCo into a Grails build so a failing threshold stops the release instead of exposing the gap after deployment.

Version the chart independently of the application, bump the version field with every change, and publish to a repository your cluster can pull from. During deployment use helm upgrade --install with --atomic and --wait so a failed upgrade rolls itself back rather than leaving a half-applied release, and keep the release history available for helm rollback when a regression only appears under load. The same pipeline promotes the identical chart from staging to production by changing values, which removes the temptation to hand-edit manifests late at night.

Scale for commuter peaks and watch the app

A Grails application serving bookings, quotes or dashboards rarely needs the same number of pods at 3am as it does at 8am on a weekday. Scale horizontally with a HorizontalPodAutoscaler driven by CPU and memory, and add custom metrics through the Prometheus adapter if you want to scale on request rate, queue depth or Grails-supplied Micrometer readings. During the morning peak on Sydney's rail network or on Melbourne's tram corridors, autoscaling can react within minutes, while a PodDisruptionBudget plus topology spread constraints keep the service available when nodes are drained or a zone goes quiet.

Measuring movement through a system is a common way to understand capacity. A companion piece on station movement analytics describes how passenger flows are captured in train and bus stations, and that kind of workload has an unpredictable request profile that autoscaling handles far better than a fixed replica count. On the observability side, write logs to standard output as structured JSON so the platform can collect them, expose Prometheus metrics for the JVM and the Grails domain, and ship traces with OpenTelemetry when you need to follow a request across several services. Dashboards and alerts belong in the same pipeline as the chart, because a deployment nobody can watch is a deployment nobody trusts.

Secure the chain and meet Australian obligations

Kubernetes widens the attack surface, so tighten the chart rather than leaving defaults in place. Pin images by digest, scan them with a tool such as Trivy before release, run pods as non-root with a read-only root filesystem, drop all Linux capabilities, and apply NetworkPolicies so only the ingress controller and internal services can reach the Grails pods. Remove the default service account, grant the deployment account the minimum role it needs, and turn on encryption for Secrets in etcd. Each of these controls belongs in the templates and values, which means they are versioned, reviewable and inherited by every new environment you create.

Australian privacy and security obligations shape the runtime configuration too. Under the Privacy Act 1988 and the Australian Privacy Principles, personal information collected by a Grails application must be handled, secured and disclosed correctly, including in Kubernetes logs and traces, where a stray request body can quietly become stored personal information. If the application stores Australian data, keep it in Australian regions and check cross-border transfer rules before adding an overseas analytics endpoint. Update the application's privacy policy to describe what you now collect and how it is handled, and align the deployment checklist with the Australian Cyber Security Centre's Essential Eight so the operational controls match the standard your organisation reports against.

Take the next step with a working chart

The fastest way to internalise this workflow is to run it end to end on a local kind cluster, then repeat it against a managed cluster in a real region. Grails Example publishes step-by-step video tutorials and written articles covering the Grails framework and Groovy, including container builds, testing and coverage tooling, and deployment practice, so you can fill the gaps without guessing at syntax. Choose a small Grails application, package the image, write the chart's Deployment and Service templates, and set the values for one environment; once that release feels comfortable, add the autoscaler, the policies and the pipeline. Start with the tutorial series, and turn your first Grails service into a managed Helm release this week.