Woody1193
Woody1193

Reputation: 8010

Change the secret a Kubernetes deployment expects

I've been having a recurring problem with a deployment for a particular pod, fooserviced, recently. I usually get a CreateContainerConfigError when I update the pod, and the detail given is Error: secrets "fooserviced-envars" not found. I'm not sure when I named the file this poorly but so far the only solution I've found is to re-add the environment variables file using

kubectl create secret generic fooserviced-envars --from-env-file ./fooserviced-envvars.txt 

So now, when I do kubectl get secrets I see both fooserviced-envars and fooserviced-envvars. I'd like to change the deployment to use fooserviced-envvars; how would I do this?

Upvotes: 0

Views: 473

Answers (2)

yogy fresta rahmawan
yogy fresta rahmawan

Reputation: 227

  1. Make sure that secret is on the same namespace. otherwise you cannot use it
  2. If you want to change deployment, change your kubernetes deployment yaml file . e.g.
env:
   - name: POSTGRES_DB_URL
     valueFrom: 
        secretKeyRef:
          key: postgres_db_url
          name: fooserviced-envars

then kubectl apply your_deployment_file

Upvotes: 1

Arghya Sadhu
Arghya Sadhu

Reputation: 44687

You can edit the deployment via kubectl edit deployment deploymentname which will open an editor and you can change the secret there live.

Another way to do this would be to run kubectl get deployment deploymentname -o yaml > deployment.yaml which will give you the yaml file and you can edit it in your editor and kubectl apply the modified yaml.

Upvotes: 2

Related Questions