Quick revision
The short answer
I would keep services portable by design rather than by a migration plan: configuration comes from the environment, services are stateless, health endpoints are standard, and application code never calls Kubernetes APIs directly. We package everything as standard OCI images, which most serverless and container platforms can run. Because serverless platforms favour fast start-up and scale to zero, we keep our Java choices compatible with that, for example AOT-friendly frameworks and start-up optimisation. And when a move is proposed, we evaluate it with a cost and risk analysis per workload, not only on technology.
What to remember
In this answer, we kept the option of moving Spring services from Kubernetes to another runtime by making portability a property of everyday code: configuration from the environment, stateless services, standard health endpoints and no Kubernetes APIs in application code, enforced by architecture tests. We packaged everything as standard OCI images, kept Java choices compatible with the fast start-up serverless platforms favour, and evaluated any move per workload class with a cost and risk analysis and a pilot, not only on technology.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would keep services portable by design rather than by a migration plan: configuration comes from the environment, services are stateless, health endpoints are standard, and application code never calls Kubernetes APIs directly. We package everything as standard OCI images, which most serverless and container platforms can run. Because serverless platforms favour fast start-up and scale to zero, we keep our Java choices compatible with that, for example AOT-friendly frameworks and start-up optimisation. And when a move is proposed, we evaluate it with a cost and risk analysis per workload, not only on technology.
Why this question is asked
Platforms change about every five to ten years, and pricing, team skills and vendor strategy change faster. A company that runs hundreds of Spring services on Kubernetes today should be able to move some of them to a serverless platform, or another orchestrator, without rewriting them. Interviewers ask this leadership question because the cheapest moment to keep that option is now, through ordinary engineering rules, and the most expensive moment is when the move is already decided. In this answer, we will define what portability means, see the coding rules that preserve it, look at packaging, understand what serverless asks of Java, and decide how to evaluate a move.
1What Portability Means Here
Portability does not mean every service can move to any platform tomorrow at no cost. It means the cost of moving is mostly in the deployment layer, manifests, pipelines and platform configuration, and not in application code. A service that reads its configuration from environment variables, exposes health over HTTP, keeps no state on local disk and speaks to the outside world only through standard protocols can run on Kubernetes, on Cloud Run, on ECS or on a VM with little change.
So the strategy is a set of rules about what application code may depend on, enforced in ordinary code review and architecture checks, plus a habit of evaluating platform options with numbers.
- Application codeno platform APIs; config, health, logs via standards
- Framework and librariesSpring Boot, Micrometer, OpenTelemetry
- PackagingOCI image, built by the standard pipeline
- Deployment layerHelm chart today, another descriptor tomorrow
- PlatformKubernetes today, maybe serverless later
5 layers, from the top down. Step through them one at a time.
A move should only change the bottom two layers.
2Coding Rules That Keep Services Portable
The rules are familiar from the twelve-factor approach, and each has a concrete reason. Configuration comes from the environment, environment variables or mounted files, which every platform can provide, and never from calls to the Kubernetes API for ConfigMaps. Services are stateless: sessions in a shared store, files in object storage, so any instance can be killed or started anywhere. Health is exposed through Actuator's standard endpoints, which any platform's health check can call. Logs go to stdout and traces and metrics use OpenTelemetry or Micrometer, which every vendor can ingest.
The rule that needs most attention is avoiding tight coupling to Kubernetes APIs inside application code. Libraries such as Spring Cloud Kubernetes, leader election through Kubernetes leases, or service discovery through the Kubernetes API are convenient, but they tie the code to the platform. Where we need such features, we put them behind a small interface or, better, leave them to the platform: DNS for discovery, mounted files for configuration, and a database lock or a scheduler service for leader election. An ArchUnit test that forbids imports of io.fabric8 or io.kubernetes in application modules turns the rule into a build failure.
3Standard Packaging
OCI images are the common package format across platforms. Kubernetes runs them, and so do Cloud Run, AWS App Runner and ECS, Azure Container Apps, and AWS Lambda, which accepts container images as well as zip packages. As long as our images are standard, with a single process, an entrypoint, configuration from the environment and a port from the PORT variable or configuration, they can be deployed elsewhere without a new build system.
We avoid packaging tricks that only work on one platform, such as relying on sidecars for core function, init containers that prepare files the application cannot start without, or host paths. If a service needs those, its portability cost is higher, and that should be a known, recorded decision.
4What Serverless Asks of Java
Serverless platforms change one thing that matters a lot for Java: instances are started on demand, often from zero, and billed by the time they run. A Spring Boot service that needs 6 seconds to start and 30 more to warm up turns every scale-out into slow requests and every idle period into either cold starts or paying for minimum instances. Request-based concurrency and short-lived instances also make long background work and in-memory caches less useful.
So keeping the option means keeping our Java choices compatible with fast start-up. Spring Boot's AOT processing and GraalVM native images can bring start-up down to under a second, at the cost of build time and limits on reflection and dynamic proxies; JVM-based options such as class data sharing, CRaC-based snapshots on platforms that support them, and the ahead-of-time cache in recent JDKs improve start-up while keeping the JIT. We do not need to switch now, but we keep code AOT-friendly, avoid heavy classpath scanning and runtime bytecode tricks, and measure start-up time as a tracked metric for each service.
5Evaluating a Move With Cost and Risk
When someone proposes moving services, we decide per workload class, with numbers. A spiky API with long idle periods, running 20 replicas at 10 percent average utilisation, may cost a third on a scale-to-zero platform; a steady, high-throughput service often costs more there than on a well-used cluster. Batch jobs and event handlers are typical good candidates; long-running stateful or latency-critical services usually are not.
- Workload profiletraffic shape, utilisation, start-up time
- Cost on each platformcompute, minimum instances, egress, operations
- Riskscold starts, limits, lock-in, skills, observability
- Pilot on 2 or 3 servicesmeasure latency, cost, incidents
- Clear benefit for this class?YesMove this class, keep the restNoStay, revisit in a year
5 steps in order. Play them, or step through them one at a time.
6Weighing the Non-Technical Side
The analysis also counts what is easy to forget: the cost of running two platforms during a transition, retraining, new on-call runbooks, observability that works differently, platform limits such as request timeouts and maximum memory, and the lock-in of the new platform itself, which may be stronger than Kubernetes. A move that saves 30 percent of compute but adds a second platform for years may not pay off. As a leader, my job is to make sure the option stays cheap through everyday rules, and that the decision to use it is made on evidence from a pilot rather than on enthusiasm for the new platform.
7Follow-up questions
Is Kubernetes itself not the portability layer?
To a large extent, yes: Kubernetes runs on every major cloud and on premises, so staying on it keeps options between providers. But it is not portable to serverless platforms that do not expose its APIs. Keeping application code free of Kubernetes specifics protects both kinds of move.
Should we build native images now, just in case?
Not for every service. Native builds cost build time, need reachability metadata and change debugging. It is cheaper to keep code AOT-friendly, run a native build for a few services in CI to catch problems early, and switch individual services when a real workload benefits, such as functions or scale-to-zero services.
How do we keep teams from adding Kubernetes dependencies anyway?
With an architecture test in the shared build that fails on imports of Kubernetes client libraries in application modules, a review checklist, and, most importantly, platform features that make those dependencies unnecessary, such as configuration through mounted files and discovery through DNS. Exceptions are recorded with their reason.
8Conclusion
In this answer, we kept the option of moving Spring services from Kubernetes to another runtime by making portability a property of everyday code: configuration from the environment, stateless services, standard health endpoints and no Kubernetes APIs in application code, enforced by architecture tests. We packaged everything as standard OCI images, kept Java choices compatible with the fast start-up serverless platforms favour, and evaluated any move per workload class with a cost and risk analysis and a pilot, not only on technology.
Open with
My approach is to keep the move cheap through everyday engineering rules, so we never need a big migration project to have the option. First, services stay portable: configuration comes from environment variables or mounted files, services are stateless with sessions and files in shared stores, health is exposed through Actuator's standard endpoints, logs go to stdout and telemetry uses OpenTelemetry or Micrometer.
Then, if they want more
Second, application code does not call Kubernetes APIs. Libraries for config, discovery or leader election through the Kubernetes API are convenient but tie the code to the platform, so I prefer DNS, mounted files and database locks, and I would add an architecture test that fails on Kubernetes client imports.
Third, packaging stays standard OCI images, which Cloud Run, ECS, Container Apps and even Lambda can run.
Fourth, I would be honest that serverless favours fast start-up and scale to zero, which is a weak spot for a classic Spring Boot service, so we keep code AOT-friendly, track start-up time per service, and try native images or JVM start-up optimisations on a few services.
Finally, any actual move would be decided per workload class with a cost and risk analysis: utilisation, cold starts, platform limits, the cost of running two platforms, skills and the new lock-in, confirmed by a pilot on two or three services.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your company runs Spring services on Kubernetes today. How would you keep the option of...": https://scrivio-interview-library.netlify.app/spring-boot/packaging-and-deployment/6f6c7d3c17/