Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On kubernetes helm how to replace a pod with new config values

I am using helm charts to deploy pods with a "ConfigMap" managing the configurations.

I edit ConfigMap directly to make changes to configuration files and then delete pods using kubectl delete, for the new configuration to take effect.

Is there any easy way using helm to replace a running pod with the new configuration without executing "kubectl delete" command

like image 949
user227321 Avatar asked May 30 '17 17:05

user227321


People also ask

How do I change the configuration pod in Kubernetes?

Edit PODs and Deployments Run the kubectl edit pod <pod name> command. This will open the pod specification in an editor (vi editor). Then edit the required properties.

How do you overwrite a helm value?

You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.


3 Answers

We have found that using --recreate-pods will immediately terminate all running pods of that deployment, meaning some downtime for your service. In other words, there will be no rolling update of your pods.

The issue to address this in Helm is still open: https://github.com/kubernetes/helm/issues/1702

Instead helm suggests adding a checksum of your configuration files to the deployment in an annotation. That way the deployment will have a different hash and essentially look 'new' to helm, causing it to update correctly.

The sha256sum function can be used to ensure a deployment's annotation section is updated if another file changes:

kind: Deployment
spec:
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
[...]

From the docs here: https://helm.sh/docs/charts_tips_and_tricks/#automatically-roll-deployments-when-configmaps-or-secrets-change

like image 73
Oliver Nicolaas Ponder Avatar answered Oct 21 '22 16:10

Oliver Nicolaas Ponder


If you need a rolling update instead of immediatly terminating pods, add

date: "{{ .Release.Time.Seconds }}"

into the spec/template/metadata/labels.

The release will then have a config change, which triggers a rolling update if set as spec/stategy/type.

In case you just changed a ConfigMap or Secret, have a look at https://helm.sh/docs/developing_charts/#automatically-roll-deployments-when-configmaps-or-secrets-change

like image 32
Dagger87 Avatar answered Oct 21 '22 14:10

Dagger87


You can run

helm upgrade --recreate-pods

to do this.

like image 33
Oliver Avatar answered Oct 21 '22 16:10

Oliver