I want to perform rolling update in Kubernetes by only changing env variables. like changing env variable from CACHE_SIZE=10
to
CACHE_SIZE=100
while the base image is the same.
Issue: i don't want to delete pod and service. Just want to restart all the pods with new env variable.
UPDATE : Want to change the env variable via kubernetes API
Issue: i don't want to delete pod and service. Just want to restart all the pods with new env variable.
First of all there is not such a thing as Pod restart in a literal sense. It may sound quite confusing as you can often hear/read about Pod restart e.g. in context of Pod
restartPolicy
. Pods are designed as relatively ephemeral, disposable entities and restarting a Pod
basically means recreating it.
No matter how you provide your env variables, either using ConfigMap that is meant to be read by your Pods
or directly in Pod
template in Deployment
definition, Pods
need to be recreated. They will be technically same Pods
based on the same template, same image etc. but they will be completely new instances with their own unique names.
As to Service
you don't have to delete it. Changes made in Pod
template specification and recreating them don't affect the Service
. Same when Pods
are recreated to re-read changed Secrets
or ConfigMaps
.
You could restart the deployment with a command like
kubectl -n your-name-space rollout restart deployment/your-deployment
This will keep using the same image tag but will restart/recreate the pod with the new ENV variables assuming you are reading it from Secrets
or ConfigMaps
.
The Deployment system checksums the entire pod template provided triggers a rolling update on any change, env var or otherwise.