How to delete or overwrite a secret in OpenShift?

Paulo Merson picture Paulo Merson · Jan 30, 2017 · Viewed 11.9k times · Source

I'm trying to create a secret on OpenShift v3.3.0 using:

oc create secret generic my-secret --from-file=application-cloud.properties=src/main/resources/application-cloud.properties -n my-project

Because I created the same secret earlier, I get this error message:

Error from server: secrets "my-secret" already exists

I looked at oc, oc create and oc create secret options and could not find an option to overwrite the secret when creating it.

I then tried to delete the existing secret with oc delete. All the commands listed below return either No resources found or a syntax error.

oc delete secrets -l my-secret -n my-project
oc delete secret -l my-secret -n my-project
oc delete secrets -l my-secret 
oc delete secret -l my-secret 
oc delete pods,secrets -l my-project
oc delete pods,secrets -l my-secret
oc delete secret generic -l my-secret

Do you know how to delete a secret or overwrite a secret upon creation using the OpenShift console or the command line?

Answer

Álvaro Pérez Soria picture Álvaro Pérez Soria · Jan 30, 2017

"my-secret" is the name of the secret, so you should delete it like this:

oc delete secret my-secret

Add -n option if you are not using the project where the secret was created