Configuration and cloud-native extensions

Mid-level Differentiator 3 min

On this page

The question

Which MicroProfile specifications does Quarkus support, and how do you use Config, Health and Fault Tolerance?

30-second answer

Quarkus implements MicroProfile through SmallRye. Config is built in: inject values with @ConfigProperty or a @ConfigMapping interface, and override them with environment variables. Health, from quarkus-smallrye-health, serves liveness and readiness endpoints from @Liveness and @Readiness beans. Fault Tolerance adds retries, timeouts, a circuit breaker, bulkheads and fallbacks to bean methods, through annotations such as @Retry. OpenAPI, REST Client and JWT (JSON Web Token) work the same way.

Understand it

MicroProfile specs as Quarkus extensions

Tap the parts

Select a part to see what it does.

Tap a specification or extension. Each row shows what a running service gets from it, and the stripe shows whether it is a MicroProfile specification.

View as text

A legend tells MicroProfile specifications apart from extensions specific to Quarkus. Seven rows follow, each with a button, a colored stripe, and two short lines.

Config, MicroProfile spec: @ConfigProperty, built into Quarkus. MicroProfile Config, through SmallRye Config, is built in.

Health, MicroProfile spec: /q/health/live, /q/health/ready. quarkus-smallrye-health serves liveness and readiness endpoints.

Fault tolerance, MicroProfile spec: @Retry, @Timeout, @CircuitBreaker. quarkus-smallrye-fault-tolerance adds @Retry, @Timeout, @CircuitBreaker, @Bulkhead and @Fallback to bean methods.

REST Client, MicroProfile spec: Typed HTTP client, @RegisterRestClient. quarkus-rest-client turns an annotated interface into an HTTP client during the build.

OpenAPI, MicroProfile spec: /q/openapi, Swagger UI in dev. quarkus-smallrye-openapi builds an OpenAPI document from your endpoints and serves it at /q/openapi.

Metrics, Quarkus extension: Micrometer, /q/metrics. Quarkus recommends Micrometer rather than MicroProfile Metrics.

Kubernetes, Quarkus extension: kubernetes.yml, probes wired in. quarkus-kubernetes writes target/kubernetes/kubernetes.yml during the build, with a Deployment and a Service.

A legend tells MicroProfile specifications apart from extensions specific to Quarkus. Seven rows follow, each with a button, a colored stripe, and two short lines.

Config, MicroProfile spec: @ConfigProperty, built into Quarkus. MicroProfile Config, through SmallRye Config, is built in.

Health, MicroProfile spec: /q/health/live, /q/health/ready. quarkus-smallrye-health serves liveness and readiness endpoints.

Fault tolerance, MicroProfile spec: @Retry, @Timeout, @CircuitBreaker. quarkus-smallrye-fault-tolerance adds @Retry, @Timeout, @CircuitBreaker, @Bulkhead and @Fallback to bean methods.

REST Client, MicroProfile spec: Typed HTTP client, @RegisterRestClient. quarkus-rest-client turns an annotated interface into an HTTP client during the build.

OpenAPI, MicroProfile spec: /q/openapi, Swagger UI in dev. quarkus-smallrye-openapi builds an OpenAPI document from your endpoints and serves it at /q/openapi.

Metrics, Quarkus extension: Micrometer, /q/metrics. Quarkus recommends Micrometer rather than MicroProfile Metrics.

Kubernetes, Quarkus extension: kubernetes.yml, probes wired in. quarkus-kubernetes writes target/kubernetes/kubernetes.yml during the build, with a Deployment and a Service.

Takeaway: Each MicroProfile specification arrives as an extension, through SmallRye. Add only what the service needs, and the build wires endpoints, probes and manifests for it.

What each extension gives a running serviceConfig reads values from environment variables and files. Health serves liveness and readiness endpoints. Fault Tolerance adds retries, timeouts and circuit breakers. The Kubernetes extension writes a manifest with probes.A QuarkusserviceConfig: values fromenv and filesHealth: live andready endpointsFault Tolerance:retry,timeout, breakerKubernetes: amanifest with probes
What each extension gives a running serviceConfig reads values from environment variables and files. Health serves liveness and readiness endpoints. Fault Tolerance adds retries, timeouts and circuit breakers. The Kubernetes extension writes a manifest with probes.A QuarkusserviceConfig: values fromenv and filesHealth: live andready endpointsFault Tolerance:retry,timeout, breakerKubernetes: amanifest with probes
What each extension gives a running service

In code

@RegisterRestClient(configKey = "prices")
@Path("/prices")
public interface PriceApi {

    @GET
    @Path("/{sku}")
    BigDecimal get(@RestPath String sku);
}

@ApplicationScoped
public class PriceService {

    @Inject
    @RestClient
    PriceApi prices;

    @Retry(maxRetries = 2, delay = 200) // a GET: safe to retry
    @Timeout(1000)
    @Fallback(fallbackMethod = "listPrice")
    public BigDecimal price(String sku) {
        return prices.get(sku);
    }

    BigDecimal listPrice(String sku) {
        return BigDecimal.TEN;
    }
}
A typed REST (Representational State Transfer) client, called with retries, a timeout and a fallback
@Readiness
@ApplicationScoped
public class PricesReady implements HealthCheck {

    @Override
    public HealthCheckResponse call() {
        return HealthCheckResponse.up("prices-api");
    }
}

@ConfigMapping(prefix = "checkout")
public interface CheckoutConfig {
    Duration holdFor();

    @WithDefault("3")
    int maxItems();
}
A readiness check, and typed configuration
quarkus.rest-client.prices.url=http://prices:8080
checkout.hold-for=15M
quarkus.kubernetes.replicas=3
Client URL, settings, and the generated manifest
How a readiness probe reaches your checkThe Kubernetes extension writes a manifest whose readiness probe calls the health endpoint. The kubelet calls it, Quarkus runs every readiness bean, and if one reports down, the pod stops receiving traffic but keeps running.The build writeskubernetes.ymlThe kubelet calls/q/health/readyQuarkus runs every@Readiness beanOne reports DOWN:no traffic, butthe pod stays up
How a readiness probe reaches your checkThe Kubernetes extension writes a manifest whose readiness probe calls the health endpoint. The kubelet calls it, Quarkus runs every readiness bean, and if one reports down, the pod stops receiving traffic but keeps running.The build writeskubernetes.ymlThe kubelet calls/q/health/readyQuarkus runs every@Readiness beanOne reports DOWN:no traffic, butthe pod stays up
How a readiness probe reaches your check

Solve it

Every rolling deploy fails about 2% of requests

During each Kubernetes rollout, clients see a burst of connection resets and 503s, then everything recovers. The pods stop as soon as they receive SIGTERM. Make deploys invisible to clients.

  1. Know the race. On delete, Kubernetes sends SIGTERM and removes the pod from the service endpoints at the same time. For a moment, traffic still arrives at a pod that is already stopping.
  2. Delay the stop. A preStop sleep of a few seconds runs before SIGTERM, so load balancers stop routing to the pod first.
  3. Finish what is in flight. quarkus.shutdown.timeout lets running requests complete after SIGTERM, instead of cutting them off.
  4. Fit inside the grace period. terminationGracePeriodSeconds must exceed the preStop sleep plus the shutdown timeout, or Kubernetes kills the pod with SIGKILL first.
  5. Check. Run a steady load test across a rollout: zero errors.
quarkus.shutdown.timeout=20s
application.properties: let in-flight requests finish
spec:
  terminationGracePeriodSeconds: 40       # more than 10 s preStop + 20 s shutdown
  containers:
    - name: orders
      lifecycle:
        preStop:
          exec:
            command: ["sleep", "10"]      # endpoints update before SIGTERM arrives
The deployment: stop routing first, then shut down, within the grace period

How to answer

  • Each specification is an extension, so the build includes only what you add.
  • Liveness answers whether to restart the pod; readiness whether to send it traffic.
  • Fault Tolerance defaults come from the specification, such as a 1 second timeout.
  • Quarkus recommends Micrometer for metrics, rather than MicroProfile Metrics.

Common mistakes

  • Putting a database check in liveness. A restart cannot fix the database, so pods restart in a loop.
  • Retrying a call that is not idempotent, such as a payment, with no key to detect duplicates.

Follow-up questions

What does the Quarkus Kubernetes extension do?

It generates Kubernetes manifests during the build. With quarkus-kubernetes, the build writes target/kubernetes/kubernetes.yml with a Deployment and a Service, using the image name and ports of the app. If the health extension is present, it adds liveness and readiness probes that call its endpoints. You tune it with quarkus.kubernetes.* properties, and quarkus.kubernetes.deploy=true applies it.

  • A container image extension, such as Jib or Docker, builds the image in the same build.
  • Variants exist for OpenShift, Minikube and Kind.
  • quarkus-kubernetes-config reads ConfigMaps and Secrets as configuration.

See it in the infographic: MicroProfile specs as Quarkus extensions

In what order do configuration sources win?

By ordinal, highest first: system properties at 400, environment variables at 300, a .env file at 295, then application.properties at 250. A profile prefix such as %prod. sets a value for one profile. An environment variable is the property in upper case, with dots as underscores, such as QUARKUS_DATASOURCE_JDBC_URL.

Check yourself

1. A readiness check calls the database, and the database goes down. What does Kubernetes do with the pod?
Show answers
  • Stops sending it traffic, and leaves it running: Correct. Readiness controls traffic. The pod rejoins once the check reports up again.
  • Restarts it: Incorrect. Only a failing liveness probe restarts a pod.
  • Nothing, since probes only log: Incorrect. Kubernetes acts on probes. A failing readiness probe takes the pod out of the Service.