Published on

Updating a Secret in Kubernetes

Authors

Today I had to update the details of a secret I had deployed in an environment. I assumed I could simply just create the secret again:

kubectl create secret generic my-secret --from-literal=key1='supersecret' --from-literal=key2='topsecret'

But that did not work, it gave an error to the affect that the secret already existed.

After doing a bit of googling I found that the secret needed to be deleted and recreated. In the absence of a better approach this is what I went with. One thing to watch out for is that any apps that use this secret may need to be restarted. In the end the final commands I used are:

kubectl delete secret my-secret

kubectl create secret generic my-secret --from-literal=key1='supersecret' --from-literal=key2='topsecret'