Video in progress

How do you plan the migration of a large Java monolith running on VMs to Kubernetes?

First I put the monolith into a container without changing it, run it in parallel with the VMs, and move traffic over step by step. Splitting the architecture is a separate, later project. The main risks are state (files, sessions), memory settings, and operational habits.

📖 Answer

Many teams want to do both at once: move to Kubernetes and split into microservices. Two big risks pile up, so I separate them.

  1. Preparation: making the app "container-friendly":
  • files written to the local disk (uploads, exports): object storage or a PVC;
  • the HTTP session in memory: Spring Session + Redis, or sticky sessions temporarily;
  • configuration from files on the VM to env/ConfigMap;
  • logs from a file to stdout;
  • if cron ran on the VM: a CronJob, or ShedLock inside the app;
  • health endpoints, graceful shutdown.

All of this is deployed and verified on the VM before the move.

  1. Measure resources: on a VM with 32 GiB RAM and -Xmx24g, in Kubernetes that is one big pod. Splitting into more, smaller replicas may be better, but it changes GC and cache behavior. It is verified with a load test.

  2. Run in parallel: the VMs and the pods side by side behind the load balancer. Traffic goes 5% → 50% → 100%. Both sides connect to the same DB, so account for the connection limit: as the number of pods grows, the sum of the Hikari pools may exceed the DB limit.

  3. Turning off the VMs: after several weeks of stable running, and kept for a while as a rollback path.

Operational readiness is often harder than the technology: the on-call team has to know how to debug with kubectl, take dumps, and find logs in the new place. Training and runbooks before the move.

And an honest question: what does Kubernetes give this monolith? If the answer is only "everyone is doing it", an automated deploy on VMs may be enough.