|
| 1 | +# Grove In-Place Restart Demo (ConfigMap-Triggered) |
| 2 | + |
| 3 | +This demo uses Kubernetes 1.35+ **RestartAllContainers** to trigger in-place restarts of all Pods in a Grove **PodCliqueSet** via a single **ConfigMap** field `restartGeneration`. Pod names, IDs, and IPs stay the same (no rescheduling). |
| 4 | + |
| 5 | +## Use case: restart without rescheduling |
| 6 | + |
| 7 | +Sometimes we want a **PodCliqueSet** (or all its Pods) to restart **without going through rescheduling**—for example when **upgrading container image versions** or when we need a clean re-run of init containers and main containers while keeping the same Pod identity and placement. |
| 8 | + |
| 9 | +Deleting and recreating Pods is costly: it involves the scheduler, node allocation, and re-initialization of networking and storage. Kubernetes 1.35’s [Restart All Containers](https://kubernetes.io/blog/2026/01/02/kubernetes-v1-35-restart-all-containers/) feature provides an **in-place** restart instead: the kubelet restarts all containers in the Pod while preserving the Pod’s UID, IP address, volumes, and node assignment. Init containers run again in order, then all main containers start with a fresh state—so an image update or configuration change can take effect without any rescheduling. This demo shows how to trigger that in-place restart for an entire Grove PodCliqueSet at once via a ConfigMap. |
| 10 | + |
| 11 | +## Idea |
| 12 | + |
| 13 | +- Each Pod runs a **restart-watcher** sidecar (Go). It uses in-cluster config to poll the ConfigMap `grove-restart-control` in the same namespace for the key `restartGeneration`. |
| 14 | +- When it sees `restartGeneration` **increase**, the watcher exits with a configured code (default 88), which triggers **RestartAllContainers** for that Pod. |
| 15 | +- To trigger a batch in-place restart, **kubectl patch** the ConfigMap to increment `restartGeneration`; all Pods with the watcher will see the new value on the next poll and restart in place. |
| 16 | + |
| 17 | +## Directory layout |
| 18 | + |
| 19 | +``` |
| 20 | +imageupdate_demo/ |
| 21 | +├── src/ |
| 22 | +│ ├── main.go # restart-watcher sidecar source |
| 23 | +│ └── go.mod |
| 24 | +├── Dockerfile # build watcher image |
| 25 | +├── Makefile # build and push image |
| 26 | +├── manifests/ |
| 27 | +│ ├── namespace.yaml |
| 28 | +│ ├── rbac.yaml # SA + Role + RoleBinding (read ConfigMap) |
| 29 | +│ ├── configmap.yaml |
| 30 | +│ └── podcliqueset.yaml |
| 31 | +└── README.md |
| 32 | +``` |
| 33 | + |
| 34 | +## Prerequisites |
| 35 | + |
| 36 | +1. **Cluster**: Kubernetes **1.35+** with **RestartAllContainersOnContainerExits** and **NodeDeclaredFeatures** enabled. Both feature gates must be enabled on **both** the API server and the kubelet. **RestartAllContainersOnContainerExits** depends on **NodeDeclaredFeatures**, so enable them together. See your cluster or distribution docs for how to set feature gates. |
| 37 | +2. **Grove**: CRD and Operator installed. If you use features like `startsAfter`, configure **GROVE_INIT_CONTAINER_IMAGE**. |
| 38 | +3. **Registry**: A Docker registry you can push the `restart-watcher` image to and that cluster nodes can pull from. |
| 39 | + |
| 40 | +## Demo steps |
| 41 | + |
| 42 | +### 1. Build and push the restart-watcher image |
| 43 | + |
| 44 | +From the repo root `imageupdate_demo/`: |
| 45 | + |
| 46 | +```bash |
| 47 | +# Set your registry (required) |
| 48 | +export REGISTRY=your-registry.io/your-user |
| 49 | +export IMAGE_TAG=latest |
| 50 | + |
| 51 | +make push |
| 52 | +``` |
| 53 | + |
| 54 | +Note the image name, e.g. `$(REGISTRY)/restart-watcher:$(IMAGE_TAG)`. |
| 55 | + |
| 56 | +### 2. Set the watcher image in the PodCliqueSet |
| 57 | + |
| 58 | +Edit `manifests/podcliqueset.yaml` and replace both `WATCHER_IMAGE` with the image you pushed, e.g.: |
| 59 | + |
| 60 | +```bash |
| 61 | +sed -i "s|WATCHER_IMAGE|${REGISTRY}/restart-watcher:${IMAGE_TAG}|g" manifests/podcliqueset.yaml |
| 62 | +``` |
| 63 | + |
| 64 | +Or change `image: WATCHER_IMAGE` to e.g. `image: your-registry.io/your-user/restart-watcher:latest` by hand. |
| 65 | + |
| 66 | +### 3. Deploy namespace, RBAC, ConfigMap, and PodCliqueSet |
| 67 | + |
| 68 | +```bash |
| 69 | +kubectl apply -f manifests/namespace.yaml |
| 70 | +kubectl apply -f manifests/rbac.yaml |
| 71 | +kubectl apply -f manifests/configmap.yaml |
| 72 | +kubectl apply -f manifests/podcliqueset.yaml |
| 73 | +``` |
| 74 | + |
| 75 | +### 4. Wait for Pods to be ready |
| 76 | + |
| 77 | +The PodCliqueSet has **pca** (replicas=2) and **pcb** (replicas=4), 6 Pods in total: |
| 78 | + |
| 79 | +```bash |
| 80 | +kubectl get podcliqueset -n grove-restart-demo |
| 81 | +kubectl get pods -n grove-restart-demo -l app.kubernetes.io/part-of=grove-restart-demo-pcs -o wide |
| 82 | +``` |
| 83 | + |
| 84 | +Confirm all 6 Pods are `Running`. |
| 85 | + |
| 86 | +### 5. (Optional) Record Pod name, Pod ID, and IP |
| 87 | + |
| 88 | +To compare before and after the trigger (names, UIDs, and IPs should stay the same): |
| 89 | + |
| 90 | +```bash |
| 91 | +kubectl get pods -n grove-restart-demo -l app.kubernetes.io/part-of=grove-restart-demo-pcs \ |
| 92 | + -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.uid}{"\t"}{.status.podIP}{"\n"}{end}' |
| 93 | +``` |
| 94 | + |
| 95 | +### 6. Trigger one “full PodCliqueSet in-place restart” |
| 96 | + |
| 97 | +Increment the ConfigMap `grove-restart-control` key `restartGeneration`: |
| 98 | + |
| 99 | +```bash |
| 100 | +# Get current value |
| 101 | +current=$(kubectl get configmap grove-restart-control -n grove-restart-demo -o jsonpath='{.data.restartGeneration}') |
| 102 | +next=$((current + 1)) |
| 103 | + |
| 104 | +# Patch with next value |
| 105 | +kubectl patch configmap grove-restart-control -n grove-restart-demo \ |
| 106 | + --type merge \ |
| 107 | + -p "{\"data\":{\"restartGeneration\":\"${next}\"}}" |
| 108 | +``` |
| 109 | + |
| 110 | +Within the next poll interval (default 5 seconds), all Pods with the restart-watcher will see the new value, exit with 88, and trigger RestartAllContainers for their Pod. |
| 111 | + |
| 112 | +### 7. Observe |
| 113 | + |
| 114 | +After about 10–20 seconds: |
| 115 | + |
| 116 | +```bash |
| 117 | +kubectl get pods -n grove-restart-demo -l app.kubernetes.io/part-of=grove-restart-demo-pcs -o wide |
| 118 | +``` |
| 119 | + |
| 120 | +**Expected**: |
| 121 | + |
| 122 | +- Pod **names and IPs unchanged** (no new Pods created or deleted). |
| 123 | +- **Restart counts** increased (e.g. `kubectl get pod <name> -n grove-restart-demo -o jsonpath='{range .status.containerStatuses[*]}{.name} restarts={.restartCount}{"\n"}{end}'`). |
| 124 | + |
| 125 | +To trigger again, repeat step 6 (increment `restartGeneration` again). |
| 126 | + |
| 127 | +### 8. Cleanup |
| 128 | + |
| 129 | +```bash |
| 130 | +kubectl delete -f manifests/podcliqueset.yaml |
| 131 | +kubectl delete -f manifests/configmap.yaml |
| 132 | +kubectl delete -f manifests/rbac.yaml |
| 133 | +kubectl delete -f manifests/namespace.yaml |
| 134 | +``` |
| 135 | + |
| 136 | +## Environment variables (restart-watcher) |
| 137 | + |
| 138 | +| Variable | Meaning | Default | |
| 139 | +|----------|---------|--------| |
| 140 | +| `CM_NAMESPACE` | ConfigMap namespace | Prefer `metadata.namespace` via fieldRef | |
| 141 | +| `CM_NAME` | ConfigMap name | `grove-restart-control` | |
| 142 | +| `KEY_NAME` | Key name | `restartGeneration` | |
| 143 | +| `POLL_INTERVAL_SECONDS` | Poll interval (seconds) | `5` | |
| 144 | +| `TRIGGER_EXIT_CODE` | Exit code that triggers RestartAllContainers | `88` | |
| 145 | + |
| 146 | +## References |
| 147 | + |
| 148 | +- Kubernetes 1.35: [Restart All Containers](https://kubernetes.io/blog/2026/01/02/kubernetes-v1-35-restart-all-containers/), [KEP-5532](https://kep.k8s.io/5532) |
0 commit comments