I want to use the kubectl create secret command to identify if the created secret is existing or not existing then if it is existing it will not create the existing secret.
currently I have this command:
kubectl create secret generic test-key --dry-run=client --output=name >/dev/null 2>&1 || echo "Secret does not exist, creating secret." && kubectl create secret generic test-key --from-literal=testkey="mysecret"
I tried running this command but I'm getting this error message saying "error: failed to create secret secrets "test-key" already exists"
I did resolve this issue by using this command below:
kubectl create secret generic my-test-key --from-file=/home/mac/testing/test-key --dry-run=client -o yaml | kubectl apply -f -
this command overwrite the existing secret. this resolve my issue as this will overwrite my created secret previously.