Kubectl change secret with kubectl patch

?
S
Bash

After updating the secret restart controller or delete the pod, *Kubernetes will automatically create a new one (assuming it's managed by a Deployment, StatefulSet, or similar controller), and the new pod will pick up the updated secret value.

1kubectl patch secret coding-cloud-backend-secrets -p '{"data":{"OPENAI_API_KEY":"'$(echo -n 'sk-***' | base64)'"}}'
2kubectl rollout restart deployment <your-deployment-name>

Created on 10/9/2025