Skip to content

Commit bb1247f

Browse files
stuggiclaude
andcommitted
[b/r] Use Deployments instead of bare Pods for PVC pinning
Deployments auto-restart pods if evicted, which is important during manual restore procedures where there may be a longer gap between creating the dummy consumers and running the PVC restore. Also removes debug tasks from playbook and keeps playbook and manual docs in sync for validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5099546 commit bb1247f

2 files changed

Lines changed: 62 additions & 34 deletions

File tree

docs/dev/backup-restore/restore/README.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,12 @@ done
223223
# mysql-db-openstack-galera-1:master-1
224224
# mysql-db-openstack-galera-2:master-2
225225

226-
# 3. Create dummy pods BEFORE the PVC restore.
226+
# 3. Create dummy Deployments BEFORE the PVC restore.
227227
# Pods referencing non-existent PVCs stay Pending until the restore creates
228228
# the PVCs. The scheduler then annotates the PVC with the selected node,
229229
# triggering WaitForFirstConsumer binding on the target node.
230+
# Using Deployments (not bare Pods) ensures automatic restart if a pod
231+
# gets evicted during longer manual procedures.
230232
# IMPORTANT: Use nodeSelector (not nodeName) so the pod goes through the
231233
# scheduler — nodeName bypasses it and the PVC annotation never gets set.
232234
for pvc_node in \
@@ -241,26 +243,39 @@ for pvc_node in \
241243
node="${pvc_node##*:}"
242244

243245
cat <<EOF | oc apply -f -
244-
apiVersion: v1
245-
kind: Pod
246+
apiVersion: apps/v1
247+
kind: Deployment
246248
metadata:
247249
name: pvc-pin-${pvc}
248250
namespace: openstack
249251
labels:
250252
app: pvc-pin
251253
spec:
252-
nodeSelector:
253-
kubernetes.io/hostname: ${node}
254-
containers:
255-
- name: pause
256-
image: registry.k8s.io/pause:3.9
257-
volumeMounts:
258-
- name: data
259-
mountPath: /data
260-
volumes:
261-
- name: data
262-
persistentVolumeClaim:
263-
claimName: ${pvc}
254+
replicas: 1
255+
strategy:
256+
type: Recreate
257+
selector:
258+
matchLabels:
259+
app: pvc-pin
260+
pvc: ${pvc}
261+
template:
262+
metadata:
263+
labels:
264+
app: pvc-pin
265+
pvc: ${pvc}
266+
spec:
267+
nodeSelector:
268+
kubernetes.io/hostname: ${node}
269+
containers:
270+
- name: pause
271+
image: registry.k8s.io/pause:3.9
272+
volumeMounts:
273+
- name: data
274+
mountPath: /data
275+
volumes:
276+
- name: data
277+
persistentVolumeClaim:
278+
claimName: ${pvc}
264279
EOF
265280
done
266281

@@ -275,8 +290,8 @@ oc apply -f 01-restore-order-00-pvcs.yaml
275290
# 6. Monitor progress
276291
oc get datadownload -n openshift-adp -w
277292

278-
# 7. After all DataDownloads complete, delete dummy pods
279-
oc delete pods -n openstack -l app=pvc-pin
293+
# 7. After all DataDownloads complete, delete dummy Deployments
294+
oc delete deployment -n openstack -l app=pvc-pin
280295
```
281296

282297
**Alternative: Immediate StorageClass.** If you don't need to control which node

docs/dev/backup-restore/restore/restore-openstack.yaml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,31 +227,44 @@
227227
msg: "{{ pvc_node_mapping.stdout_lines }}"
228228
when: pin_pvcs | bool and pvc_node_mapping.stdout != ""
229229

230-
- name: Create dummy pods to pin PVCs to nodes
230+
- name: Create dummy Deployments to pin PVCs to nodes
231231
ansible.builtin.shell: |
232232
PVC_NAME="{{ item.split(':')[0] }}"
233233
NODE_NAME="{{ item.split(':')[1] }}"
234234
cat <<EOF | oc apply -f -
235-
apiVersion: v1
236-
kind: Pod
235+
apiVersion: apps/v1
236+
kind: Deployment
237237
metadata:
238238
name: pvc-pin-${PVC_NAME}
239239
namespace: {{ openstack_namespace }}
240240
labels:
241241
app: pvc-pin
242242
spec:
243-
nodeSelector:
244-
kubernetes.io/hostname: ${NODE_NAME}
245-
containers:
246-
- name: pause
247-
image: registry.k8s.io/pause:3.9
248-
volumeMounts:
249-
- name: data
250-
mountPath: /data
251-
volumes:
252-
- name: data
253-
persistentVolumeClaim:
254-
claimName: ${PVC_NAME}
243+
replicas: 1
244+
strategy:
245+
type: Recreate
246+
selector:
247+
matchLabels:
248+
app: pvc-pin
249+
pvc: ${PVC_NAME}
250+
template:
251+
metadata:
252+
labels:
253+
app: pvc-pin
254+
pvc: ${PVC_NAME}
255+
spec:
256+
nodeSelector:
257+
kubernetes.io/hostname: ${NODE_NAME}
258+
containers:
259+
- name: pause
260+
image: registry.k8s.io/pause:3.9
261+
volumeMounts:
262+
- name: data
263+
mountPath: /data
264+
volumes:
265+
- name: data
266+
persistentVolumeClaim:
267+
claimName: ${PVC_NAME}
255268
EOF
256269
echo "Created pvc-pin-${PVC_NAME} on ${NODE_NAME}"
257270
loop: "{{ pvc_node_mapping.stdout_lines }}"
@@ -300,9 +313,9 @@
300313
restore_name: "openstack-restore-00-pvcs-{{ restore_suffix }}"
301314
step_name: "Step 1 (PVC restore)"
302315

303-
- name: Delete dummy pods after PVC restore
316+
- name: Delete dummy Deployments after PVC restore
304317
ansible.builtin.shell: |
305-
oc delete pods -n {{ openstack_namespace }} -l app=pvc-pin --ignore-not-found=true
318+
oc delete deployment -n {{ openstack_namespace }} -l app=pvc-pin --ignore-not-found=true
306319
changed_when: true
307320
when: pin_pvcs | bool
308321

0 commit comments

Comments
 (0)