Skip to content

Stop Kubernetes Deployments Before Local Dev

Use this recipe to avoid running the same workload in Kubernetes and on your laptop at the same time.

The approach is a local-dev guardrail: execute a Kubernetes scale-down step as a oneshot prerequisite before local services start.

Pattern: scale deployment(s) to zero first

Section titled “Pattern: scale deployment(s) to zero first”
{
"services": {
"pause-cluster-api": {
"kind": "oneshot",
"cmd": [
"kubectl",
"--context",
"dev-cluster",
"--namespace",
"payments",
"scale",
"deployment/payments-api",
"--replicas=0"
]
},
"api": {
"cmd": ["pnpm", "--dir", "services/api", "dev"],
"dependsOn": ["pause-cluster-api"],
"ready": {
"type": "http",
"url": "http://127.0.0.1:3000/health"
}
},
"web": {
"cmd": ["pnpm", "--dir", "web", "dev"],
"dependsOn": ["api"]
}
}
}

dependsOn ensures local api will not start until the scale command exits successfully.

If the scale command fails, dependents are blocked and startup does not silently continue.

  • Always pin --context and --namespace in the command.
  • Never run this pattern against production contexts.
  • Keep this recipe for local development only.
  • If your team needs automatic restore, define a separate explicit resume command outside this stack startup path.
  1. Run kubectl config current-context and confirm expected context.
  2. Confirm namespace and deployment names.
  3. Start FlowLayer only after those checks.

If you need to stop several deployments, keep each target explicit in command arguments. Avoid broad selectors in this startup gate.

For dependency planning, see Startup Waves. For local readiness gates after scale-down, see Readiness and Examples.