How to update environment variables in a StatefulSet

7/18/2018

I wants to update the environment variables in a Kubernetes StatefulSet. I Updated the YAML file and executed $kubectl apply -f my-statefulset.yml, but nothing changed. Then I tried $kubectl scale sts my-statefulset --replicas=0; kubectl scale sts my-statefulset --replicas=4 and it only recreated the last pod in the StatefulSet.

Dropping my entire StatefulSet and recreating it just to change an environment variable does not looks like a good idea. $kubectl patch could work here, but I was not able to form the update json. I need a little help here on how to update environment variables in StatefulSet.

-- Nitish mittal
kubernetes
kubernetes-statefulset

1 Answer

7/18/2018

If your StatefulSet name is my-statefulset, the below command should help you:

kubectl patch statefulset my-statefulset -p '{"spec":{"updateStrategy":{"type":"RollingUpdate"}}}'

More information you can find in Updating StatefulSets document.

-- Akar
Source: StackOverflow