Change the secret a Kubernetes deployment expects

2/3/2020

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?

-- Woody1193
kubernetes

2 Answers

2/3/2020
  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
-- yogy fresta rahmawan
Source: StackOverflow

2/3/2020

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.

-- Arghya Sadhu
Source: StackOverflow