Search code examples
kuberneteskubectl

Update deployment fails when same name exists in separate namespaces


I've used the following command to update the image run in a deployment:

kubectl --cluster websites --namespace production set image 
deployment/mobile-web mobile-web=eu.gcr.io/websites/mobile-web:0.23

This worked well until I created a staging namespace mirroring the production environment. In other words the deployment mobile-web exists both in the production and staging namespace. Now I get the error:

Error from server: the server could not find the requested resource
(get deployments.extensions mobile-web)

What am I missing here? Or is the only way to update using a yaml- or JSON-file, which means a bit more work on the CI/CD pipeline? I've tried setting the namespace with:

kubectl config set-context production --namespace=production --cluster=websites

but to no avail.


Solution

  • The solution for my concern was to kill the current proxy and get new credentials and start the proxy again:

    gcloud container clusters get-credentials websites kubectl proxy --port=8080

    Now either commands work as expected:

    kubectl get deployment mobile-web --namespace=production kubectl get deployment mobile-web --namespace=staging

    However it doesn't explain why it stopped working in the first place.