Search code examples
kubernetesjenkinsdeploymentkubernetes-helm

How to trigger to re-creation of deployment without any command


Apologies in advance, I am quite new to Kubernetes, we have some Helm charts that we use to implement monitoring stacks to various environments using Kubernetes. I am updating the helm charts versions and one version, in particular, requires deployment to be re-created.

I tried running

kubectl delete deployment <deploymentname>

and then implementing the update which works but I need a way to trigger deployment creation from values.yaml file so that it triggers in all of the environments we have when I run the pipeline instead of me going to all of them manually and deleting deployments beforehand.

I also tried adding an annotation like

annotations:
  kubectl.kubernetes.io/restartedAt:

but that didn't work.

The error I am getting :

13:40:55  2023-02-22 13:40:55,354 - ERROR  -
Command 'kubectl --kubeconfig=/tmp/tmpxv384dq8 apply --validate=False
-f /tmp/tmp9ku4lg20' failed with: The Deployment "pgw-prometheus-pushgateway" 
is invalid: spec.selector: Invalid value:
v1.LabelSelector{MatchLabels:map[string]string{"app.kubernetes.io/instance":"pgw",
"app.kubernetes.io/name":"prometheus-pushgateway"},
MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable

Solution

  • So basically the solution I found was overriding the deployment name. I added fullnameOverride value to values yaml file (this is provided in the helm charts values) and changed the name slightly from the previous and that deleted the old deployment and created the new one without me doing kubectl delete deploy beforehand.