WebSphere Tutorial · WebSphere Liberty · Lesson 12 of 23

Liberty in Containers and Kubernetes

Building Liberty container images, configuring them per environment, health probes on Kubernetes, the Open Liberty Operator and InstantOn.

Members can save this page, take notes and track progress. See membership · Sign in

A container image

FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal
COPY --chown=1001:0 src/main/liberty/config/ /config/
RUN features.sh                          # install only the features server.xml lists
COPY --chown=1001:0 target/orders.war /config/apps/
RUN configure.sh                         # finish the image (caches, optional InstantOn checkpoint setup)
  • Configuration differences come from environment variables, ConfigMaps and Secrets mounted into the container (Liberty reads ${env.X} and variable files).
  • Logs go to the console in JSON with WLP_LOGGING_CONSOLE_FORMAT=json for central log systems.
  • Size the JVM relative to the container's memory limit and leave room for native memory.

On Kubernetes

Use MicroProfile Health for probes: /health/started for a startup probe, /health/live for liveness and /health/ready for readiness. The Open Liberty Operator (or WebSphere Liberty Operator) manages OpenLibertyApplication resources: deployment, service, route, autoscaling, certificates and day-2 operations such as collecting dumps.

InstantOn

InstantOn checkpoints a started server while the image is built (using CRIU) and restores it at container start, cutting start-up time sharply: useful for scale-to-zero and fast autoscaling.

Leaving room for native memory in a containerTry it yourself
container_limit_mb = 1024
for heap_percent in [50, 75, 90]:
    heap = container_limit_mb * heap_percent // 100
    native_left = container_limit_mb - heap
    risk = "OOMKilled risk" if native_left < 250 else "ok"
    print(f"-XX:MaxRAMPercentage={heap_percent}: heap {heap} MB, {native_left} MB for threads, metaspace, JIT -> {risk}")

Output

-XX:MaxRAMPercentage=50: heap 512 MB, 512 MB for threads, metaspace, JIT -> ok
-XX:MaxRAMPercentage=75: heap 768 MB, 256 MB for threads, metaspace, JIT -> ok
-XX:MaxRAMPercentage=90: heap 921 MB, 103 MB for threads, metaspace, JIT -> OOMKilled risk

Test yourself

Which endpoint should a Kubernetes readiness probe call on Liberty?

  1. /metrics
  2. /health/ready
  3. /openapi
  4. /ibm/api
Show answer

Answer: /health/ready

MicroProfile Health's readiness endpoint reports whether the server can take traffic.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake