Using Micronaut with Kubernetes (K8s)

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.

Using Micronaut with Kubernetes

🧰 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:

πŸ“ Project Overview

This will generate:

πŸ‘¨β€πŸ’» Step 2: Add a Simple Controller

File: HelloController.java

βš™οΈ Step 3: Build JAR with Maven

Run:

The JAR will be created at:

🐳 Step 4: Create Dockerfile

Add a Dockerfile:

πŸ— Step 5: Build Docker Image

If you’re using Minikube, make sure Docker points to Minikube:

Then rebuild:

πŸ“„ Step 6: Write Kubernetes YAML Files

1. deployment.yaml

2. service.yaml

πŸš€ Step 7: Deploy to Kubernetes

Check status:

🌐 Step 8: Access the Service

If using Minikube:

Or manually:

Expected response:

πŸ§ͺ Optional: Health Check Endpoint

Add to application.yml:

Micronaut will expose /health at:

πŸ“š 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.