Fixating "skaffold dev" to a context

12 views
Skip to first unread message

William Estoque

unread,
Oct 14, 2025, 4:25:50 AM (9 days ago) Oct 14
to skaffold-users
I was wondering how people are fixating a specific context to "skaffold dev" command. As far as I know, there's no real way to do this via skaffold.yaml.

The closest to this is to run with the --kube-context command: skaffold dev --kube-context=custom

I recently had a frustration where I had a production cluster with the context name "prod" and I accidentally run skaffold dev in this context so it deleted my load balancers, volumes and other configuration in production!

tldr; I think there should be a way to force "skaffold dev" to only run in a specific context to avoid mistakes like the above in the future.

Brian de Alwis

unread,
Oct 14, 2025, 8:50:51 AM (9 days ago) Oct 14
to William Estoque, skaffold-users
My 2¢:don't have access to prod.  If you have to, separate the cluster credentials to a separate ~/.kube/config-prod file and bring it in only when necessary with the `KUBECONTEXT` environment variable.  But the safest approach is to make human access virtually impossible — breakglass situations only — and instead rely on automation like Cloud Deploy to drive deployments to prod (which supports using Skaffold to do so).

Brian.

--
You received this message because you are subscribed to the Google Groups "skaffold-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skaffold-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/skaffold-users/a7985a24-2a61-4003-a2da-c7b373681d12n%40googlegroups.com.

William Estoque

unread,
Oct 14, 2025, 12:50:42 PM (9 days ago) Oct 14
to skaffold-users
Thanks for your response. I actually like deploying to prod from my machine via skaffold using "skaffold run -p prod" especially when testing different configurations. My concern was with my workflow involving switching contexts when developing and also when deploying. I think it would be nice if skaffold has the kubeContext config at a dev/run level in skaffold.yaml to force it to run only when in a specific context. I can submit changes to accomplish this but curious if it's also helpful to other people? Maybe I'm overthinking this and I should just have a CI tool deploy from the get go but it would need significant setup vs just testing config and pushing from my machine. Also, my kubernetes cluster is in Hetzner Cloud and I'm not using a managed kubernetes cluster so I won't have access to Cloud Deploy.

Tim Hardy

unread,
Oct 15, 2025, 6:00:28 PM (8 days ago) Oct 15
to skaffold-users
Excellent question. There should definitely be a first class feature to handle this in skaffold. It doesn't have to be prod. Wiping out dev resources when you meant to simply run locally can generate a ton of work, and it is easily handled. I'm disappointed skaffold doesn't have one or more features to prevent these scenarios.

Here is how I handle it in my monorepo:
I have the following start script in package.json - devs just run "npm start" to launch...
    "start": "node pre-skaffold-checks.js && skaffold dev --no-prune=false --cache-artifacts=false",

In pre-skaffold-checks.js, I check to see if docker is running, then I check the context. If the context is not "docker-desktop", I write to the console, "Wrong context!!! Use docker-desktop", then just stop - process.exit(0). If everything's good (context is local), I exit with a success - process.exit(1), and the skaffold command actually runs.

It took me wiping out all resources on dev twice before I buckled down and implemented the above. I've never had to worry about it since.

William Estoque

unread,
Oct 15, 2025, 11:44:31 PM (7 days ago) Oct 15
to skaffold-users
Thanks! A pre-check script is a similar solution I am leaning towards to but it is not ideal. 

I have submitted a PR that should help us if approved: 


This will now show an error like:

$ skaffold dev
creating runner: creating deployer: kubectl context mismatch: current context is "hetzner" but deploy.kubeContext is set to "custom" in skaffold.yaml. This prevents accidental deployments to the wrong cluster. To deploy to "hetzner", switch your context with: kubectl config use-context custom
Reply all
Reply to author
Forward
0 new messages