I have a devops pipeline divided in three steps:
kubectl apply -f configmap.yml
kubectl apply -f deployment.yml
kubectl rollout restart deployment/test-service
I think that when the configmap.yml
changes the rollout restart
step is useful. But when only the deployment.yml
changes, I'm worried that the "extra" rollout restart
step is not useful and should be avoided.
Should I execute rollout restart
only when the configmap.yml
changes or should I don't care about?
Best practice is to annotate the deployment's pod with the hash of the configmap. If the content of the configmap changes, the annotation changes and all pods will be rolling updated. If the configmap doesn't change, nothing will happen.
E.g. with helm:
annotations:
checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
from grafana example.
If you're not using helm you can have a script create the hash in your pipeline.
By that the rollout restart step is not required anymore. Pods will restart always if the configmap and/or the deployment changes. Otherwise nothing happens.