Kubernetes (K8s) is the standard for deploying and managing containerized applications in the cloud. Micronaut, with its fast startup, small memory footprint, and easy cloud integration, is a great match for Kubernetes.
In this post, youโll learn everything about Using Micronaut with Kubernetes:
- Create a Micronaut app
- Package it with Docker
- Write Kubernetes YAML files
- Deploy to a K8s cluster
- Access the service via NodePort
We will use the package com.kscodes.micronaut.kubernetes throughout.

๐งฐ What You Need
- Java 17+
- Docker installed
- Minikube or a local K8s cluster (for testing)
- Maven 3.6+
- kubectl installed
- Micronaut CLI (optional)
๐ฆ Step 1: Create Micronaut App
Generate a Micronaut app with Maven:
mn create-app com.kscodes.micronaut.kubernetes.helloservice \
--build maven \
--jdk 17
๐ Project Overview
This will generate:
.
โโโ src/main/java/com/kscodes/micronaut/kubernetes/HelloController.java
โโโ src/main/resources/application.yml
โโโ pom.xml
๐จโ๐ป Step 2: Add a Simple Controller
File: HelloController.java
package com.kscodes.micronaut.kubernetes;
import io.micronaut.http.annotation.*;
@Controller("/hello")
public class HelloController {
@Get
public String greet() {
return "Hello from Micronaut on Kubernetes!";
}
}
โ๏ธ Step 3: Build JAR with Maven
Run:
./mvnw clean package
The JAR will be created at:
target/helloservice-0.1.jar
๐ณ Step 4: Create Dockerfile
Add a Dockerfile:
FROM eclipse-temurin:17-jdk-jammy
WORKDIR /app
COPY target/helloservice-*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
๐ Step 5: Build Docker Image
docker build -t micronaut-k8s-app .
If you’re using Minikube, make sure Docker points to Minikube:
eval $(minikube docker-env)
Then rebuild:
docker build -t micronaut-k8s-app .
๐ Step 6: Write Kubernetes YAML Files
1. deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: micronaut-deployment
spec:
replicas: 1
selector:
matchLabels:
app: micronaut-app
template:
metadata:
labels:
app: micronaut-app
spec:
containers:
- name: micronaut-container
image: micronaut-k8s-app
ports:
- containerPort: 8080
2. service.yaml
apiVersion: v1
kind: Service
metadata:
name: micronaut-service
spec:
type: NodePort
selector:
app: micronaut-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 30007
๐ Step 7: Deploy to Kubernetes
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
Check status:
kubectl get pods
kubectl get svc
๐ Step 8: Access the Service
If using Minikube:
minikube service micronaut-service
Or manually:
curl http://localhost:30007/hello
Expected response:
Hello from Micronaut on Kubernetes!
๐งช Optional: Health Check Endpoint
Add to application.yml:
endpoints:
health:
enabled: true
sensitive: false
Micronaut will expose /health at:
http://localhost:30007/health
๐ External Resources
โ Conclusion
Using Micronaut with Kubernetes allows you to build scalable, fast, and cloud-ready Java apps. With Micronautโs small footprint and Kubernetesโ power, your services can deploy quickly and reliably.
By following this guide with Maven and the custom package com.kscodes.micronaut.kubernetes, youโre set up for both local testing and production deployment in the cloud.