Skip to content

install: add a liveness probe to the Envoy sidecars of Substrate - #735

Merged
mayawang merged 1 commit into
google:mainfrom
YoyinZyc:fix-697-stuck-rollout
Nov 25, 2026
Merged

mayawang merged 1 commit into
google:mainfrom
YoyinZyc:fix-697-stuck-rollout

Conversation

@YoyinZyc

@YoyinZyc YoyinZyc commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #697

Root cause:

ax local start only re-applies unchanged manifests, which creates no new pod, and then waits on the stuck one.

agent-substrate/substrate#3601
The root cause is on substrate end. When only the atenet-router container restarts (the kubelet restarts single containers, not pods), the router's shutdown sequence has already told Envoy to fail its health check (POST /healthcheck/fail). The new router process never undoes that, and Envoy itself never restarted, so it reports DRAINING and 503 on /ready forever. Kubernetes does not repair it: the envoy container has a readiness probe but no liveness probe, and a Deployment does not replace a pod for being unready. atenet-egress has the same problem.

Fix on Ax

  1. Adds a liveness probe on /ready to the envoy container of atenet-router and atenet-egress when it renders the Substrate manifests (RenderSystemBundle, new RenderEgressBundle). The kubelet then restarts a drained Envoy by itself, with no need to run ax local start again. A container that already has a liveness probe keeps it, so this steps aside once Substrate ships its own.
  2. Rollout errors name the pod and container that is running but not ready, and print the kubectl rollout restart commands.

The probe is ·initialDelaySeconds: 30, periodSeconds: 10, failureThreshold: 6·: Envoy is restarted after 60 seconds of 503. Envoy also answers 503 while it starts, and the window leaves it time for that.

Test

1. kill atenet-router to trigger container recreation
➜  ax git:(fix-697-stuck-rollout) ✗ docker exec $N pkill -TERM -f 'router --mode=ingress'

2. envoy container is not ready
➜  ax git:(fix-697-stuck-rollout) ✗ kubectl --context $C -n ate-system get pod -l app=atenet-router
NAME                             READY   STATUS    RESTARTS        AGE
atenet-router-58db677747-czjsc   1/2     Running   3 (2m19s ago)   72m

3. watch the killing event
➜  ax git:(fix-697-stuck-rollout) ✗ kubectl -n ate-system get events --sort-by=.lastTimestamp | grep -E 'liveness|Killing'
12m         Normal    Killing     pod/atenet-router-54bb6c897f-vpgvg   Container envoy failed liveness probe, will be restarted

4. both router and envoy sidecar are back to running after restart
➜  ax git:(fix-697-stuck-rollout) ✗ kubectl -n ate-system get pod -l app=atenet-router -w
NAME                             READY   STATUS    RESTARTS      AGE
atenet-router-54bb6c897f-vpgvg   2/2     Running   4 (11m ago)   73m

@mayawang mayawang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean root-cause writeup and tests. Since restartStuckDeployments works around agent-substrate/substrate#3601, let's link that issue in the code and docs so we know when it's safe to remove. Left a couple of small notes inline on scope, threshold, and Envoy draining.

Comment thread internal/install/substrate/bootstrap.go Resolved
Comment thread internal/install/substrate/bootstrap.go Resolved
Comment thread skills/substrate/SKILL.md Resolved
Comment thread internal/install/substrate/bootstrap.go Resolved
@rakyll

rakyll commented Nov 24, 2026

Copy link
Copy Markdown
Member

Let's file an issue tracking agent-substrate/substrate#3601, and fix the force restart once it's closed.

@rakyll

rakyll commented Nov 24, 2026

Copy link
Copy Markdown
Member

Instead of restarting stuck pods in ax local start, could RenderSystemBundle add a liveness probe on /ready to the envoy container of atenet-router, with a generous threshold? The kubelet would then restart a drained Envoy automatically, whenever it happens.

`ax local start` could not recover when a pod of Agent Substrate ran but
never became ready. It applied the unchanged manifests, which creates no
new pod, waited for the same pod, and failed with "timed out waiting for
the condition".

The case in google#697 is the envoy container of atenet-router. When only the
router container next to it restarts, its shutdown sequence has already
failed Envoy's health check and drained its listeners, and nothing sets
that back (agent-substrate/substrate#3601).
Kubernetes does not repair the pod: the envoy process is alive and has
only a readiness probe, and the pod still matches its Deployment.
atenet-egress has the same defect.

Bootstrap now adds a liveness probe on /ready to the envoy container of
atenet-router (RenderSystemBundle) and atenet-egress (RenderEgressBundle),
so the kubelet restarts a drained Envoy by itself. A container that has a
liveness probe already keeps it. The probe fails after 60 seconds of 503.
Envoy also answers 503 while it starts, and the window leaves it time for
that. A pod that is being deleted is not affected: the kubelet runs no
liveness probe on it.

alreadyHealthy now requires the pods of every workload that Bootstrap
waits for. It did not look at atenet-egress, so a cluster with a stuck
egress pod was reported healthy and Bootstrap returned. A cluster
installed before this change gets the probe the next time Bootstrap
applies the manifests.

The rollout status and the timeout error now name a container that runs
but is not ready, and the error gives the command that restarts the
workload. This also applies to `ax install`.

Tested on a new Kind cluster: after SIGTERM to the router process, the
kubelet restarted envoy and the pod was ready again without another
`ax local start`, in 132 seconds for atenet-router and 117 seconds for
atenet-egress.

Fixes google#697
@YoyinZyc

Copy link
Copy Markdown
Collaborator Author

Instead of restarting stuck pods in ax local start, could RenderSystemBundle add a liveness probe on /ready to the envoy container of atenet-router, with a generous threshold? The kubelet would then restart a drained Envoy automatically, whenever it happens.

Yeah, we could do that and clean it up later. Also filed issue #755 to track.

@YoyinZyc

Copy link
Copy Markdown
Collaborator Author

@mayawang @rakyll please take another look. Thanks

@mayawang mayawang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, clean switch to the liveness probe and thanks for filing #755 for cleanup. Two quick nits before merging: update the PR title to match the new commit, and consider adding Fixes #754 since it hits the same drained Envoy state.

@YoyinZyc YoyinZyc changed the title install: restart a stuck Substrate Deployment in ax local start install: add a liveness probe to the Envoy sidecars of Substrate Nov 24, 2026
@mayawang
mayawang merged commit b81b8c1 into google:main Nov 25, 2026
11 checks passed
YoyinZyc added a commit that referenced this pull request Nov 25, 2026
Part of #754

## Problem

`ax local status` looked only at `ate-api-server` and at the `proxy_arp`
sysctl of the node. In #754 the `envoy` container of `atenet-router`
stayed unready and the `atenet-router` Service had no endpoints, so new
workspaces hung, while the status still read:

```
Substrate:     ate-api-server (1/1 available)
```

## Change

`KindProvider.Status` now reads every workload that `ax local start`
installs for Agent Substrate, with one `kubectl get
deployments,statefulsets,daemonsets -A`. When a workload has fewer
available pods than it wants, the `Substrate:` line names it instead of
`ate-api-server`:

```
Substrate:     degraded: atenet-router (0/1 available), atenet-egress (0/1 available)
```


## Not in this PR

#754 also asks that a Workspace report the unreachable router as a
condition instead of staying in `Preparing` with no conditions. Arguable
if we should let workspace to report the underlying subtrate status
especially we could potentially make workspace 100% declaritive.

## Test

On a Kind cluster built from this branch (no liveness probe from #735,
so Envoy stays drained):

```
$ ax local status --name ax-754
Cluster:       ax-754 (kind)
State:         Running
Kube Context:  kind-ax-754
Substrate:     ate-api-server (1/1 available)
AX Server:     ax-server (1/1 available in ax-system)


$ docker exec ax-754-control-plane pkill -TERM -f 'router --mode=ingress'
$ docker exec ax-754-control-plane pkill -TERM -f 'router --mode=egress'

$ kubectl --context kind-ax-754 -n ate-system get deploy atenet-router atenet-egress
NAME            READY   UP-TO-DATE   AVAILABLE
atenet-egress   0/1     1            0
atenet-router   0/1     1            0

$ ax local status --name ax-754
Cluster:       ax-754 (kind)
State:         Running
Kube Context:  kind-ax-754
Substrate:     degraded: atenet-router (0/1 available), atenet-egress (0/1 available)
AX Server:     ax-server (1/1 available in ax-system)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ax local start can't recover when the atenet-router envoy sidecar is stuck unready

3 participants