Scheduling Gates — prevent Pod scheduling until gates are opened.
1apiVersion: v12kind: Pod3metadata:4 name: gated-pod5spec:6 schedulingGates:7 - name: "scheduling.mycompany.com/approved"8 - name: "scheduling.mycompany.com/budget-check"9 containers:10 - name: app11 image: myapp:latest12 resources:13 requests:14 cpu: "2"15 memory: "4Gi"
1# Check scheduling gates2kubectl get pod gated-pod -o jsonpath='{.spec.schedulingGates}' | jq34# Open a gate5kubectl patch pod gated-pod --type=json -p '[{"op":"remove","path":"/spec/schedulingGates/0"}]'67# Check gate status8kubectl get pod gated-pod -o jsonpath='{.spec.schedulingGates}' | jq910# Watch for scheduling11kubectl get pods -w12kubectl get events --field-selector reason=Scheduled1314# Verify Pod is scheduled after gates removed15kubectl get pod gated-pod -o jsonpath='{.spec.nodeName}'
1// Controller to remove gates2func (r *ApprovalReconciler) Reconcile(ctx context.Context, req ctrl.Request) {3 var pod corev1.Pod4 if err := r.Get(ctx, req.NamespacedName, &pod); err != nil {5 return ctrl.Result{}, err6 }78 // Check approval9 if !isApproved(pod) {10 return ctrl.Result{RequeueAfter: 10 * time.Second}, nil11 }1213 // Remove gate14 pod.Spec.SchedulingGates = removeGate(pod.Spec.SchedulingGates, "scheduling.mycompany.com/approved")15 return ctrl.Result{}, r.Update(ctx, &pod)16}
Use cases: