Kubernetes
A Wow service runs on Kubernetes as a Deployment: its pods are the service's nodes, they find each other through the service's database, and other services reach them through a headless Service. Nothing else is needed: no operator, no ZooKeeper, no Kafka consumer group. Wow's Helm chart, wow-service, renders those objects for one service, and is released with Wow at Wow's version. A platform installs it once per service. This page installs the eShop's ordering service with it; Deployment Model explains the ideas behind it.
Install a service
A release takes two values files, the second over the first:
The values the build knows.
./gradlew :<server>:generateWowHelmValues, whichassembleruns, writes them from the service's contract intobuild/wow/helm/values.yaml: the service's name, after which the chart names every object; the peers whose contracts are on its class path, each with the service that hosts it (service.contractPeers); and the route its nodes serve the Manifest at. They follow the code, so never copy them by hand. The basket's:yamlservice: name: "eshop-basket-service" contractPeers: - context: "eshop-ordering" service: "eshop-ordering-service" manifest: route: "/wow/manifest"The deployment's own. The image, the ports, the replicas, the platform, the profiles, the stores and their secrets, the resources. The ordering service's, in
deploy/eshop-ordering:
# The eshop-ordering service's own values for the wow-service chart (deploy/helm/wow-service), on MongoDB and Kafka:
# what the build does not know. Pass them after the values its build generates, so they override them:
#
# ./gradlew :eshop-ordering-server:generateWowHelmValues
# helm install eshop-ordering deploy/helm/wow-service \
# -f examples/eshop/ordering/ordering-server/build/wow/helm/values.yaml -f deploy/eshop-ordering/values.yaml
#
# values-postgres.yaml after these puts the service on PostgreSQL instead.
image:
# The image built from this repository (README.md).
repository: wow-eshop-ordering-server
tag: local
# The ports of the image's own configuration (application.yaml), which the chart sets on the pod.
ports:
http: 8083
internal: 9093
# The nodes share the partitions through leases in the service's database: no ZooKeeper, no consumer group.
replicas: 2
# The internal port admits the pods of the platform, labelled app.kubernetes.io/part-of: eshop.
partOf: eshop
config:
# The mongo profile keeps the service's data on MongoDB, the replica set at secret.yaml's URI (deploy/mongodb), in a
# database of its own; the kafka profile connects it to the other contexts through Kafka; the cosec profile takes the
# callers from the CoSec gateway in front of the service.
SPRING_PROFILES_ACTIVE: mongo,kafka,cosec
WOW_KAFKA_BOOTSTRAPSERVERS: kafka:9092
# The topics the service owns are created by the operator; the node only validates them. The kafka profile's auto
# is for trying the service out.
WOW_KAFKA_DDL: validate
# Fixed once the context's log holds entries; the command topic wow.eshop-ordering.commands has as many partitions.
WOW_LOG_PARTITIONS: "64"
# Traces and metrics: the node's spans and Micrometer meters go through the OpenTelemetry Java agent, which the
# OpenTelemetry Operator injects (podAnnotations, with an Instrumentation resource in the namespace). Without the
# agent they are no-ops. It exports to the collector below over OTLP, and bridges Micrometer's global registry.
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
OTEL_INSTRUMENTATION_MICROMETER_ENABLED: "true"
# The database's connection: secret.yaml, an example to replace.
envFrom:
- secretRef:
name: eshop-ordering-service-mongo
podAnnotations:
instrumentation.opentelemetry.io/inject-java: "true"
resources:
requests:
cpu: 500m
memory: 768Mi
limits:
memory: 1Gi
# The public port admits the CoSec gateway's pods (app.kubernetes.io/component: gateway) of the release's own
# namespace, where this deployment runs its gateway: the chart renders only once the gateway's namespace is named. A
# gateway in a namespace of its own is named by it, in the entry's namespaceSelector:
# matchLabels:
# kubernetes.io/metadata.name: <the gateway's namespace>
networkPolicy:
public:
from:
- podSelector:
matchLabels:
app.kubernetes.io/component: gatewayThen install it from the OCI registry, at the Wow version the service is built with, or from a checkout of the repository (deploy/helm/wow-service):
helm upgrade --install eshop-ordering oci://ghcr.io/ahoo-wang/wow-service --version <wow-version> \
-f examples/eshop/ordering/ordering-server/build/wow/helm/values.yaml \
-f deploy/eshop-ordering/values.yaml --waitThe chart is also on oci://registry-1.docker.io/ahoowang/wow-service. Its values.schema.json holds every value to the keys the chart declares: a misspelt key fails the install, as a node refuses a wow.* key it does not know. Every value is described in the chart's values.yaml; its README lists the objects it renders.
Before you install
- Build the image and push it, or load it into a local cluster.
- Provide the database and, when the service uses it, Kafka.
deploy/mongodbholds a MongoDB replica set to start from; for PostgreSQL, passvalues-postgres.yamlaftervalues.yaml, and set the server as PostgreSQL says. - Create the Kafka topics the service owns, since
values.yamlsetsWOW_KAFKA_DDL=validate: a command topic needs exactly as many partitions as the log (Kafka). - Create the secrets
envFromnames, from the examples beside the values (secret.yaml,postgres-secret.yaml) or your own store.
deploy/eshop installs the whole eShop, a release per service.
What it renders
Every object is named after service.name, the service's spring.application.name, never after the release:
| Object | Name | Holds |
|---|---|---|
| Deployment | <name> | The nodes |
| ConfigMap | <name>-config | config as environment variables, settings as SPRING_APPLICATION_JSON, javaOpts, the shutdown's bounds |
| Service | <name> | The public HTTP port |
| Service | <name>-cluster | The internal port, headless |
| NetworkPolicy | <name>-public, <name>-internal | Who may reach each port |
| PodDisruptionBudget | <name> | How many nodes a voluntary disruption may take |
| ServiceAccount | <name> | No token mounted: the nodes call no Kubernetes API |
| HorizontalPodAutoscaler or ScaledObject | <name> | Optional: Scale |
| ServiceMonitor or PodMonitor | <name> | Optional: Monitor; a ServiceMonitor comes with a headless Service <name>-metrics |
Labels
Every object carries the chart's labels: app.kubernetes.io/name, the service's name, app.kubernetes.io/instance, app.kubernetes.io/version, app.kubernetes.io/managed-by, helm.sh/chart, and app.kubernetes.io/part-of with partOf. The pods are selected by app.kubernetes.io/name alone: the Deployment, both Services, the disruption budget, the network policies, the monitors and the topology spread select them by it, and the other services' internal policies admit them by it, as the platform's admit them by app.kubernetes.io/part-of.
podLabels adds labels of your own to the pods, and metrics.serviceMonitor.labels and metrics.podMonitor.labels to the monitors (the release label the Prometheus Operator picks them by, say). None of them may set one of the chart's labels: the render fails, naming the key. A pod label app.kubernetes.io/name would leave every selector without its pods, and any other would render a second key of the same name.
The image
The image runs the service's Gradle distribution (./gradlew :eshop-ordering-server:installDist) on a JDK 25 base, pinned by digest, as a numeric non-root user, and exposes the HTTP port and the internal port. The chart sets both ports on the pod (SERVER_PORT, WOW_INTERNAL_PORT, from ports), so the Services, the probes and the image's configuration cannot disagree.
The pod's user
The chart runs the pod as user and group 10001, the ones Wow's images declare (USER 10001), with runAsNonRoot on the pod and the container (podSecurityContext, securityContext). The user is named on the pod for the containers that other controllers add. The OpenTelemetry Operator's Java agent, which instrumentation.opentelemetry.io/inject-java asks for, is copied in by an init container whose image declares no USER. That container inherits the application container's security context, runAsNonRoot included. Without a user named on the pod it would run as root, and the kubelet refuses the pod: container has runAsNonRoot and image will run as root. With the pod's user it runs as 10001, and the pod starts.
A service whose image is built from another base, whose files belong to another id, sets that id:
podSecurityContext:
runAsUser: 1001
runAsGroup: 1001null for both leaves the user to the image again. The pod then starts only while no container without a USER of its own is added to it.
The JDK
Wow is built for JDK 21 and runs on it, but run it on JDK 25 in production. The backends make their blocking driver calls (JDBC, the MongoDB and Kafka clients) on virtual threads. Before JDK 24, a virtual thread that blocks inside synchronized code, as drivers and Java agents often do, pins the carrier thread it runs on. Enough of them at once leave no carrier for the others: every store and topic call of the node stops returning, its leases lapse, and the other nodes take its partitions. The node's liveness then fails after wow.health.liveness.stall-timeout, and Kubernetes restarts it (Health). JDK 24 and later let those threads unmount. A node on an earlier JDK warns of this once when it starts.
Memory
The chart's default javaOpts is -XX:MaxRAMPercentage=75.0 -XX:+ExitOnOutOfMemoryError: the heap is three quarters of the container's memory limit, and an OutOfMemoryError ends the process, so Kubernetes starts the pod again and the other nodes take its partitions over meanwhile. The images Wow builds set -XX:+ExitOnOutOfMemoryError too. A javaOpts of your own replaces the default: keep -XX:+ExitOnOutOfMemoryError in it. Without it the node still steps out of its lease groups on an OutOfMemoryError its own work meets, and its liveness fails until the process ends (Fatal errors), but an error elsewhere in the process, a request's say, leaves it to the JVM.
Size the heap for what a node holds at its peak, not for its average: the state cache, a tenth of the heap unless wow.state-cache.capacity bounds it (What Wow derives); the commands in flight, up to wow.executor.max-in-flight, each with the state its aggregate loads, which for an aggregate with a long history and no recent snapshot means its events replayed; and the entries each subscription holds in each partition it runs, up to its in-flight bound. A memory limit the heap cannot fit those in under load turns overload into restarts.
Shared settings
Every node of a service gets the same configuration from the ConfigMap, as environment variables that Spring Boot binds relaxed: config in the values, as the ordering's above shows, in the canonical form (wow.log.partitions is WOW_LOG_PARTITIONS). A variable cannot write the dash or the dot of a map entry's name, so such an entry (wow.peers.eshop-ordering, wow.aggregates.[shop.cart]) goes under settings as a tree, which the chart renders as SPRING_APPLICATION_JSON. That overrides every variable, so a variable cannot change a setting the tree holds; it can only add one the tree leaves out, in the legacy form, every dash of the key written as an underscore (WOW_PEERS_ESHOP_ORDERING_TIMEOUT beside the tree's eshop-ordering). The host refuses a variable that reaches no entry, or that gives the map a second one (Keys are checked). The database's connection comes from a Secret, through envFrom. The internal port needs no secret: the network is its boundary.
Service links
Unless a pod sets enableServiceLinks: false, Kubernetes gives its containers variables for each Service of its namespace. For a Service wow-kafka of cluster IP 10.96.0.12 whose first port is 9092/TCP, they are WOW_KAFKA_SERVICE_HOST=10.96.0.12, WOW_KAFKA_SERVICE_PORT=9092 and WOW_KAFKA_PORT=tcp://10.96.0.12:9092. Each port adds WOW_KAFKA_PORT_9092_TCP=tcp://10.96.0.12:9092 with its _PROTO, _PORT and _ADDR, and each named port adds WOW_KAFKA_SERVICE_PORT_<NAME>. A Service named wow-<group> therefore gives variables named for a Wow group.
The chart sets enableServiceLinks: false, so its pods have none. A pod outside the chart, in a namespace with such a Service, sees them:
- The host leaves a Service's variables alone when all of them are there and agree with one another, as Kubernetes writes them. It logs once which Services it left alone.
- A variable of their shape whose value does not agree (
WOW_KAFKA_PORT=9092) is configuration, checked as any other, so a mistyped setting cannot pass for a service link. - A Service whose variable Spring reads as a key refuses the start:
wow-internalgivesWOW_INTERNAL_PORT=tcp://10.96.0.5:9090, which Spring reads aswow.internal.port. Spring Boot binds that setting before the configuration key check runs, so the log carries its failure analysis,Failed to bind properties under 'wow.internal.port' to int, withOrigin: System Environment Property "WOW_INTERNAL_PORT". A variable of a Service that no binding before the check meets is refused by the check, underWow configuration keys read wrongly, naming the Service. SetenableServiceLinks: falseon such a pod, or name the Service otherwise.
The nodes
# A new node joins before an old one leaves: the partitions move to it through the leases, and none is left without
# an owner while the rollout runs.
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: {{ .Values.rollout.maxSurge }}
maxUnavailable: 0Two replicas are two nodes, which split the log's partitions through leases in the database. A rolling update starts a new pod before it stops an old one (maxUnavailable: 0), so the partitions always have an owner. Each node needs an identity and an address its peers can reach, which the chart gives it from the pod:
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
# The ports the Services and the probes name: the chart's, whatever the image's configuration says.
- name: SERVER_PORT
value: {{ .Values.ports.http | quote }}
- name: WOW_INTERNAL_PORT
value: {{ .Values.ports.internal | quote }}
# The node id is the pod's name: a replaced pod is a new member.
- name: WOW_NODE_ID
value: $(POD_NAME)
# The internal port binds the pod's private address only, and the node advertises that address: a
# Deployment's pods have no DNS name of their own.
- name: WOW_INTERNAL_HOST
value: $(POD_IP)
# The namespace a peer's SRV name is in, unless wow.peer.dns.namespaces places the peer elsewhere.
- name: WOW_PEER_DNS_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- with .Values.env }}
{{- toYaml . | nindent 12 }}
{{- end }}- The node id is the pod's name. A replaced pod joins as a new member; the old one's leases expire.
- The internal port binds the pod's own address, and the node advertises that address,
<pod IP>:<internal port>: the host's default, so the chart sets nowow.node.address. A Deployment's pods have no DNS name of their own: a headless service publishes<pod>.<service>records only for pods withspec.hostname, which a Deployment cannot give each pod. Setwow.node.addressonly where the pod's own address is not the one its peers reach, such as a StatefulSet whose pods have stable names (serviceNameandhostname) or a host with several interfaces. - The namespace comes from the pod (
WOW_PEER_DNS_NAMESPACE): the namespace the node looks its peers up in.
Two services
# The internal port's headless Service, named after the service with -cluster: its SRV records,
# _internal._tcp.<service>-cluster.<namespace>.svc, name every node's address, the address each node advertises (its pod
# IP), and the other services find the nodes through them. It publishes the nodes that are not ready, so a node that is
# starting or draining is still found. Never expose it outside the cluster: it takes no token, each node and service
# names itself on each request (Wow-Service), and the internal NetworkPolicy admits the platform's own pods alone.
apiVersion: v1
kind: Service
metadata:
name: {{ $name }}-cluster
labels:
{{- include "wow-service.labels" . | nindent 4 }}
spec:
clusterIP: None
publishNotReadyAddresses: true
selector:
{{- include "wow-service.selectorLabels" . | nindent 4 }}
ports:
- name: internal
port: {{ .Values.ports.internal }}
targetPort: internal
protocol: TCPBoth are named after the service. eshop-ordering-service serves the public port to the gateway, through which clients reach it. eshop-ordering-service-cluster is headless: its SRV records, _internal._tcp.eshop-ordering-service-cluster.<namespace>.svc, name every node's address, and other services find the nodes through them by the service's name alone (Calling Other Services). It publishes the nodes that are not ready, so a node that is starting or draining is still found.
Network policies
Never expose the internal port outside the cluster. It takes no token: each request names its service (Wow-Service), and the network policies are the boundary (Secure a Deployment):
networkPolicy:
enabled: true
public:
# Whether the chart tells CoSec that only the gateway can reach the public port
# (COSEC_PIPELINE_IDENTITY_ONLYGATEWAYCANREACH=true), the statement a service in wow.cosec.mode: gateway needs to
# start. It holds only while `from` names the gateway's pods alone: each pod `from` admits can claim any identity to
# such a service. The chart refuses it for an entry of `from` that names no pods by their labels (an empty or no
# podSelector, an ipBlock), which admits every pod it reaches, and for an entry that names no namespace: pod labels
# are their namespace's owner's to set, so a rule by labels in any namespace lets each namespace's owner pass as the
# gateway. Set it false when `from` admits anything else; a service in gateway mode then does not start until you
# state it yourself (where it is true) or change its mode.
onlyGateway: true
# Who reaches the public port: the gateway's pods, labelled app.kubernetes.io/component: gateway, in the gateway's
# namespace, which you name here (the chart does not render while onlyGateway is true and an entry names none). An
# entry names its namespace by kubernetes.io/metadata.name, the label Kubernetes sets to the namespace's name; leave
# the namespaceSelector out when the gateway runs in the release's own namespace.
from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ""
podSelector:
matchLabels:
app.kubernetes.io/component: gateway
internal:
# More pods that reach the internal port, besides the service's own, its platform's and its peers'.
from: []
metrics:
# Who scrapes the metrics port, when it is one of its own: Prometheus' pods, as kube-prometheus-stack labels them.
from:
- namespaceSelector: {}
podSelector:
matchLabels:
app.kubernetes.io/name: prometheus<name>-publicadmits the gateway's pods, labelledapp.kubernetes.io/component: gateway, in the gateway's namespace, to the HTTP port. Name that namespace: the chart does not render until you do, since a rule by pod labels in any namespace lets the owner of each namespace label a pod as the gateway's, and in gateway mode this rule is the service's only authentication. An entry names its namespace bykubernetes.io/metadata.name, the label Kubernetes sets to the namespace's name, in itsnamespaceSelector'smatchLabelsor as anInexpression; an entry without anamespaceSelectoradmits the pods of the release's own namespace. WhileonlyGatewayis true every entry names its namespace; with it false any rule renders but the default's unnamed one, which admits no pod. Label your gateway's pods so, or setnetworkPolicy.public.fromto match them; an empty list is refused, since it would admit every pod.yamlnetworkPolicy: public: from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: gateway podSelector: matchLabels: app.kubernetes.io/component: gateway<name>-internaladmits to the internal port the service's own nodes, the pods of its platform (partOf, which labels every objectapp.kubernetes.io/part-of), the pods of the peers it calls, which send the wait signals back, andnetworkPolicy.internal.from.
A network plugin that does not enforce NetworkPolicy ignores them; then keep the internal port off every network but the platform's by other means.
Peers in other namespaces
A peer in another namespace takes its namespace in service.peers, in your values file:
service:
peers:
- context: eshop-payment
service: eshop-payment-service
namespace: paymentsThe chart joins your service.peers with the generated service.contractPeers by service: your entry takes the generated one's place, and the generated peers your file does not name stay, since Helm would replace one list whole. A peer your file names that the contract does not is added. The chart then gives the node wow.peer.dns.namespaces.eshop-payment-service: payments, so it looks the peer up at _internal._tcp.eshop-payment-service-cluster.payments.svc, and the internal policy admits the peer's pods from that namespace. The peer's own internal policy must admit this service's pods in turn: its networkPolicy.internal.from, with a namespaceSelector.
A peer node that stops answering
A node lost without notice, such as a pod deleted by force or a machine gone, may leave its address dropping packets without a reset, and stays in the SRV records a node caches for 30 seconds. A request that goes out on a connection to it is not answered: it ends at its bound, its wait and a grace for a command or a call, wow.peer.timeout for a query, as wow.command.unknown, wow.query.timeout or wow.peer.unavailable. A command is never sent again to that node: it is sent again under the same request id at most once, and only to another live node of the context, which forwards it to the partition's owner, so its outcome is settled as a duplicate or a commit; with no other live node it fails once as wow.command.unknown. A query or a saga's call is not sent again. A connection that is not made within the bound, to an address that drops packets before the connection rather than after it, sent nothing: the request fails over to the next node as a refused one does, at most a second past the bound, and the node is not passed over.
The node's clients then pass that node over: the requests that follow to the same port of the context go to its other nodes. A saga's calls and the commands and queries of a service-mode client all go to a peer's internal port, so they share this: a query that was not answered passes the node over for the calls too. A user-mode client's requests go to the peer's public port, a list of its own, which keeps its own: whether the node answers there is for that port's requests to show. So the lost node costs one request its bound, not every request that rotates onto it until the records are read again. The node comes back:
- when it answers a request still in flight to it, whatever it answers;
- when the records are read again and still list it: it takes requests again, and if it still does not answer, it costs one more request its bound and is passed over again;
- when the records are read again without it: it is gone;
- after 30 seconds, the time the records are kept, when nothing reads them again, as with a fixed
urlor a discovery that gives no lookup of its own.
A connection it takes does not bring it back: a node that takes connections and never answers would pass that test. When every node of a context is passed over, the requests go to them all, as if none were: a request is never left unsent for it.
It is not a health check: no probe is sent, and a node that answers slowly but within the bound is never passed over. Each bypass and each return is logged once, by me.ahoo.wow.client.SilentPeers, with how long the node was passed over, and counted by wow.peer.bypass.notices (Observability).
The cluster's DNS in every zone
Every name a node resolves goes through the cluster's DNS: its stores, the Kafka brokers, the peers' SRV records, and the gateway's routes to the services. Run that DNS in every zone, one replica per zone at least, required rather than preferred. A topology spread constraint on topology.kubernetes.io/zone with whenUnsatisfiable: DoNotSchedule does it. In a three-zone cluster whose two CoreDNS replicas had landed in one zone, losing that zone left the services unable to resolve one another for 256 s, every Wow node otherwise healthy:
- the CoSec gateway answered the calls whose service it could not resolve with 500 ("Failed to resolve"), and the ingress with 502;
- a Wow node starting in that time exited, since its Kafka client found no address to start from ("No resolvable bootstrap urls given in bootstrap.servers"). It was restarted until the names resolved again.
# CoreDNS, one replica per zone: kubectl -n kube-system patch deployment coredns --type merge -p "$(cat this-file)"
spec:
replicas: 3
template:
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
k8s-app: kube-dns
# Only this ReplicaSet's pods count, so a rollout's old pods do not fill a zone.
matchLabelKeys: [pod-template-hash]Probes
The host gives the node's health to Spring Boot Actuator's readiness and liveness groups, on the HTTP port:
startupProbe:
httpGet:
path: /actuator/health/readiness
port: http
periodSeconds: {{ .Values.probes.startup.periodSeconds }}
failureThreshold: {{ .Values.probes.startup.failureThreshold }}
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: http
periodSeconds: {{ .Values.probes.readiness.periodSeconds }}
failureThreshold: {{ .Values.probes.readiness.failureThreshold }}
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: http
periodSeconds: {{ .Values.probes.liveness.periodSeconds }}
failureThreshold: {{ .Values.probes.liveness.failureThreshold }}Readiness fails while the node cannot serve: before it runs, while its log, a store its writes need (a type's own snapshot store) or its lease store is down, while it owns none of its share of partitions past the hand-over grace, or while a topic it reads is still joining. Liveness fails only when the node is stuck or has met a fatal error (Fatal errors), never for a storage outage and not while it drains, so an outage does not restart every pod at once. The startup probe gives a node three minutes to start (probes.startup). It is no longer the only thing that ends a hung start: a starting node whose reconcile finishes no step for wow.health.liveness.stall-timeout fails its liveness too (Deployment Model).
Graceful shutdown
When Kubernetes stops a pod, the node first finishes the waits still open, then hands its partitions off after the commands in flight, saves its checkpoints, and closes its internal port last. The grace period must cover all of it, so the chart derives it from the same values it gives the node:
# The node's shutdown: the grace period is the preStop pause, the public server's longest wait, the node's stop bound
# from these values and the margin, one after the other; the chart sets wow.wait.max-timeout, wow.cluster.drain-timeout
# and wow.subscription.stop-timeout from them.
shutdown:
# Time for the endpoints to drop the pod before Spring Boot stops taking requests.
preStopSeconds: 5
# The longest wait the public server finishes before it stops (wow.wait.max-timeout); at least
# wow.wait.default-timeout (10 s unless set), or the node does not start.
waitMaxTimeoutSeconds: 60
# How long a hand-off waits for its partition's commands in flight (wow.cluster.drain-timeout).
drainTimeoutSeconds: 10
# How long a subscription's stop waits for its entries in flight (wow.subscription.stop-timeout).
subscriptionStopTimeoutSeconds: 10
# Room for the checkpoints to be saved and the JVM to exit.
marginSeconds: 15The grace period counts the shutdown's steps one after the other: the preStop pause; the public server's graceful shutdown, which lasts as long as its longest request, a wait (waitMaxTimeout), and 2 seconds more before the server cuts what is still open; the node's stop, up to its stop bound; and the margin, which also covers those 2 seconds and the server's close (at most 3 seconds). That is 5 + 60 + 90 + 15 = 170 seconds by default. The stop bound is max(waitMaxTimeout, 2 × subscriptionStopTimeout + drainTimeout) + 3 × drainTimeout, 90 seconds by default, the formula of ServiceNodeOptions.stopBound and of the host's shutdown phase (Starting and stopping). Its waits are measured from the node's own stop, so they come after the public server's. The chart sets wow.wait.max-timeout, wow.cluster.drain-timeout and wow.subscription.stop-timeout from these values; setting any of them in config, in settings or in env is refused, each key read as Spring's relaxed binding reads it, and so are the ports and the node's identity the chart sets itself (server.port, wow.internal.port, wow.internal.host, wow.node.id, wow.peer.dns.namespace, and the pod's POD_NAME and POD_IP in env). A key in a Secret or ConfigMap of your envFrom is not seen by the chart: keep these keys out of them. A short preStop pause gives the endpoints time to drop the pod before Spring Boot stops taking requests.
Scale
Add replicas to spread the partitions over more nodes; remove them to gather them again. The leases move partitions between nodes as members join and leave, about one partition in N each time. A move is not free:
- The hand-off. The leaving owner finishes the partition's commands in flight, within
wow.cluster.drain-timeout, and saves its subscriptions' checkpoints. Meanwhile the commands of its aggregates wait, or run on the node that received them (Deployment Model). - The subscriptions go on from their checkpoints on the new owner, so a handler may see again what it handled after its last checkpoint.
- The state cache of the new owner is cold: each aggregate's first command there loads its snapshot and the log after it.
So scale on a signal that lasts, and slowly. A node beyond the number of partitions, 64 by default, owns none, which is one reason the count is chosen up front: keep the maximum replicas below it. The signals worth scaling on:
| Signal | Means |
|---|---|
| CPU | Command and query work, for a service whose handlers compute |
wow.subscription.backlog | Subscriptions falling behind the log: projections, sagas, Sinks |
wow.command.duration | The commands' latency, when the stores answer in time |
autoscaling.hpa makes a HorizontalPodAutoscaler on CPU, and metrics of your own:
# A HorizontalPodAutoscaler on CPU, and metrics of your own. Exclusive with keda.
hpa:
enabled: false
minReplicas: 2
maxReplicas: 8
cpuUtilization: 70
metrics: []
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 1
periodSeconds: 60
scaleDown:
stabilizationWindowSeconds: 600
policies:
- type: Pods
value: 1
periodSeconds: 300Its behavior adds a node a minute at most, and removes one every five minutes after ten quiet ones, so a burst does not move the partitions back and forth. With KEDA installed, autoscaling.keda scales on the backlog through Prometheus instead; the two are exclusive. Its minReplicas is at least 1, as the HPA's: the backlog is a series the service's own pods report, so a service at zero nodes would have no backlog to scale up on, and the schema refuses 0:
# A KEDA ScaledObject on the subscriptions' backlog, through Prometheus; needs KEDA installed. Exclusive with hpa.
keda:
enabled: false
# At least 1, as the HPA's: the only trigger is the backlog the service's own pods report, so nothing would scale
# the service up from zero.
minReplicas: 2
maxReplicas: 8
pollingInterval: 30
cooldownPeriod: 300
prometheus:
serverAddress: ""
# sum(wow_subscription_backlog{namespace="<namespace>", pod=~"<name>-.*"}) when empty.
query: ""
# The backlog per node above which a node is added.
threshold: 1000
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 1
periodSeconds: 60
scaleDown:
stabilizationWindowSeconds: 600
policies:
- type: Pods
value: 1
periodSeconds: 300The chart requires neither: both are off by default, and the replicas are then replicas.
Monitor
The nodes' spans and meters go through the OpenTelemetry Java agent (Observability), which pushes them over OTLP, as the eShop's values set it, or serves the meters on a Prometheus endpoint (OTEL_METRICS_EXPORTER=prometheus, port 9464). For the Prometheus Operator, the chart adds a ServiceMonitor or a PodMonitor on that endpoint:
# Where Prometheus scrapes a node. The OpenTelemetry Java agent's Prometheus exporter (OTEL_METRICS_EXPORTER=prometheus,
# port 9464, /metrics) is a port of its own, admitted from networkPolicy.metrics.from alone: the scraper reaches the
# meters and nothing else. Actuator's endpoint on the HTTP port (port: the HTTP port, path: /actuator/prometheus) is on
# the public port: with the NetworkPolicies on, the scraper is admitted there only through networkPolicy.public.from,
# which admits it to the service's API too, and the public port believes the CoSec-Identity of whatever reaches it.
metrics:
port: 9464
path: /metrics
serviceMonitor:
enabled: false
interval: 30s
# The monitor's own labels, beside the chart's (release: kube-prometheus-stack, say, for the Prometheus that picks
# it). None of the chart's: they are refused.
labels: {}
podMonitor:
enabled: false
interval: 30s
# As serviceMonitor.labels.
labels: {}Keep the meters on the agent's port. A metrics port of its own is opened on the pod and admitted by <name>-public from networkPolicy.metrics.from alone, Prometheus' pods by default: the scraper reaches the meters and nothing else. A monitor reads the agent's Prometheus exporter, which is off until OTEL_METRICS_EXPORTER=prometheus turns it on: the eShop's values push over OTLP instead, so set it in config before you enable a monitor.
With the meters on the HTTP port (metrics.port equal to ports.http) and the NetworkPolicies on, the scraper is admitted only through networkPolicy.public.from, which admits it to the service's API too: the public port believes the CoSec-Identity of whatever reaches it. The chart's notes say so when it renders that setup; choose it knowingly.
Give the monitor the labels your Prometheus selects (labels). What to alert on is in Observability.
Disruption budgets
A voluntary disruption, a node drained or the cluster upgraded, takes the nodes one at a time: each node that leaves hands its partitions off, and the others take them through the leases before the next one goes. The chart's PodDisruptionBudget says so, and spreads the nodes over zones and hosts:
podDisruptionBudget:
enabled: true
# Or minAvailable, which wins when given.
maxUnavailable: 1
# AlwaysAllow lets a drain evict a node that is not ready, which a budget would otherwise hold.
unhealthyPodEvictionPolicy: AlwaysAllow
topologySpread:
enabled: true
maxSkew: 1
whenUnsatisfiable: ScheduleAnywayAlwaysAllow lets a drain evict a node that is not ready, which a budget would otherwise hold for ever. Prefer maxUnavailable to minAvailable: with two replicas, minAvailable: 2 blocks every drain.
Upgrade
The chart's version is the Wow version, and its appVersion the default tag of the image. Upgrade the service's Wow dependency and the chart together, then:
helm upgrade eshop-ordering oci://ghcr.io/ahoo-wang/wow-service --version <new-wow-version> \
-f examples/eshop/ordering/ordering-server/build/wow/helm/values.yaml \
-f deploy/eshop-ordering/values.yaml --waitThe rollout replaces the nodes one at a time, a new one ready before an old one goes, so for a while two versions run side by side: Upgrades says what may, and which settings must never change, the log's partitions among them. A change of the shared settings alone rolls the nodes too: the pods carry a checksum of the ConfigMap. Regenerate the build's values with every build: a peer added in the code is then admitted by the policies and found by the node.
Reinstall on the kept stores
A release uninstalled and installed again on the stores it kept starts its new nodes only once the old ones are gone. helm uninstall --wait returns once the release's objects are deleted, while its pods are still stopping gracefully. A release installed again at that moment would run two generations of nodes on one store, which the upgrade's own rollout never does: a new node joins only through the leases the old ones hand over. Wait for the pods to be gone first:
helm uninstall eshop-ordering --wait
kubectl wait --for=delete pod -l app.kubernetes.io/instance=eshop-ordering --timeout=10mWith Kustomize
A service deploys one of two ways, both from the same chart and the same values:
- The chart, with Helm, as above:
helm installandhelm upgradefrom its OCI repository. It fits a platform that runs Helm: its releases, their history and rollback, an umbrella chart. - The base the build renders, with an overlay: the service's build renders the chart, the one the plugin carries at its own version, with the values it generates and the deployment's own, into a Kustomize base of plain YAML. An overlay changes what the chart does not derive, and
kubectl apply -kapplies it. It fits a deployment that applies plain manifests, by hand or through a GitOps tool that reads a kustomization, with no Helm on the operator's side.
The objects are the chart's either way, so the chart's schema still checks every value that feeds a derivation, and a deployment that installs the chart changes nothing. The GA end-to-end run deploys the eShop basket the second way every night (.github/ga-e2e/cluster.sh), beside the other services' releases. The basket is this section's example.
Name the deployment's values files and the namespace in the server's build. The basket's:
wow {
kubernetes {
values.from(rootProject.file("deploy/eshop-basket/values.yaml"))
values.from(
providers.gradleProperty("eshop.kubernetes.values").map { paths ->
paths.split(',').map(String::trim).filter(String::isNotEmpty).map(rootProject::file)
}.orElse(emptyList()),
)
namespace = providers.gradleProperty("eshop.kubernetes.namespace").orElse("eshop")
}
}generateWowKubernetes renders it, and is part of assemble once values names a file. The values files come after the build's own (generateWowHelmValues), each over the one before, as -f arguments do. It writes build/wow/k8s/:
build/wow/k8s/
├── kustomization.yaml the objects, and the namespace they were rendered for
├── configmap-eshop-basket-service-config.yaml
├── deployment-eshop-basket-service.yaml
├── networkpolicy-eshop-basket-service-internal.yaml
├── networkpolicy-eshop-basket-service-public.yaml
├── poddisruptionbudget-eshop-basket-service.yaml
├── service-eshop-basket-service-cluster.yaml
├── service-eshop-basket-service.yaml
└── serviceaccount-eshop-basket-service.yamlThe task is cached: the same values, namespace and Wow version render the same base on every machine. What a build says when it cannot render:
| Mistake | The build says |
|---|---|
| No values named | generateWowKubernetes renders the wow-service chart with the deployment's values, which the build names: wow { kubernetes { values.from("deploy/<service>/values.yaml") } }. |
| No namespace | generateWowKubernetes renders the service for the namespace it is deployed to, which the chart derives from (…): set wow { kubernetes { namespace = "<namespace>" } }. |
| A values file that does not exist | wow { kubernetes { values.from(…) } } names "…/deploy/eshop-basket/valeus.yaml", which does not exist: correct the path in values.from(…), or remove it. |
| A value the schema refuses | Helm refused to render the wow-service chart:, then the chart's own message, such as additional properties 'replicaz' not allowed |
The production overlay changes the image, the replicas and a limit:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../../examples/eshop/basket/basket-server/build/wow/k8s
images:
- name: wow-eshop-basket-server
newName: registry.example.com/eshop-basket
newTag: 1.4.2
replicas:
- name: eshop-basket-service
count: 3
patches:
- target:
kind: Deployment
name: eshop-basket-service
patch: |-
- op: replace
path: /spec/template/spec/containers/0/resources/limits/memory
value: 2Gi./gradlew :eshop-basket-server:assemble
kubectl apply -k deploy/eshop-basket/prodValues or patches
A value that feeds a derivation goes in the values files: the chart turns it into several objects at once, and its schema checks it. These are:
- the namespace,
kubernetes { namespace }; - the peers' namespaces,
service.peers[].namespace(Peers in other namespaces); partOf, which labels the pods and opens the internal policy to the platform;- the gateway rule,
networkPolicy.public.fromandonlyGateway, which the CoSec statement follows; - the monitors,
metricsand their policy rule; - the autoscaler,
hpaorkeda; - the shutdown bounds,
shutdown.*, which the grace period sums (Graceful shutdown); - the ports, which the Services, the policies, the probes and the node's own settings share.
Anything else is an overlay's: the image, the replicas, the resources, extra environment, labels and annotations. Nothing checks a patch beyond the API server: a port patched in one object and not the others is written as asked, and the probes fail at run time.
An overlay must not move the base to another namespace. The chart derives from the namespace (whether a peer is in another one, the autoscaler's query), so a base moved by an overlay's namespace: is wrong without any error. An environment whose namespace, or another value of the list above, differs is a render of its own: the basket's build takes both from properties, as the GA end-to-end run renders it for its cluster:
./gradlew :eshop-basket-server:generateWowKubernetes -Peshop.kubernetes.namespace=default \
-Peshop.kubernetes.values=.github/ga-e2e/services/values.yamlHelm, fetched by the build
The operator needs kubectl alone; the build renders with Helm v4.3.1, the version the plugin pins. It is fetched when generateWowKubernetes runs, never while a build is configured, from https://get.helm.sh into the Gradle user home (wow/helm/v4.3.1/<os>-<arch>/), once per machine. Its archive is refused unless its SHA-256 is the one the plugin holds, whatever served it. The plugin fetches it for Linux, macOS and Windows, on amd64 and arm64. Two Gradle properties (in gradle.properties of the user home, or -P) change where it comes from:
| Property | Means |
|---|---|
wow.helm.mirror | A mirror of https://get.helm.sh, of the same layout; the archive is still checked against the plugin's digest |
wow.helm.executable | A Helm on this machine, used only if it is exactly v4.3.1; another platform's builds set it |
A Helm on the PATH is never used, so the base does not depend on the machine. Offline, the build uses the binary it fetched before, and without one fails naming both properties.
Render again on each Wow upgrade: the chart is the plugin's, at its version.
Render with Helm, then overlay
A deployment that keeps Helm for rendering, but not for applying, renders the chart from its OCI repository with the build's values and its own, and lays its overlay over the output:
helm template eshop-ordering oci://ghcr.io/ahoo-wang/wow-service --version <wow-version> --namespace shop \
-f examples/eshop/ordering/ordering-server/build/wow/helm/values.yaml \
-f deploy/eshop-ordering/values.yaml > base/eshop-ordering.yamlList eshop-ordering.yaml among the resources of base/kustomization.yaml, set its namespace: to the one it was rendered for, and render it again on each upgrade and with each build's values. What goes in the values and what in the overlay is the same as above, and so is the namespace: an overlay does not move it.
In an umbrella chart
A platform chart holds the chart once per service, under an alias, each service's values under its alias:
dependencies:
- name: wow-service
version: <wow-version>
repository: oci://ghcr.io/ahoo-wang
alias: ordering
- name: wow-service
version: <wow-version>
repository: oci://ghcr.io/ahoo-wang
alias: basketThe schema accepts the umbrella's global values, which the chart does not read.