Is there any variable which is available in helm to get the current replica cycle value? Is there any variable which is available in helm to get the current replica cycle value? kubernetes kubernetes

Is there any variable which is available in helm to get the current replica cycle value?


No, you cannot pass a different values for every replica.

Why? Because it's in the definition of the word "replica":

replica: an exact copy of an object

Replica is an exact copy, thus you cannot make it different in any way. And kubernetes is not going to help you with it.

Answering to your other question:

How to get the current replica count? I would like to increase the replicacount of deployment by exposing replicacount value

Kubernetes applies declarative model. You declare how many replicas you want and it will do it's best to match it. You don't need to know your current count to scale it up or down (at least that's what I understand you are trying to do based on your question).

Just put the replicacount variable in the values.yaml file and reference it in helm chart. It's that easy.


If your application code looks at its own hostname (as in the shell hostname command or the C gethostname function), it will be the name of the current pod. This will be unique across every replica.

If checking the hostname is inconvenient for your code, you can also use the downward API to inject the pod name as an environment variable (example copied directly from the linked Kubernetes documentation):

env:  - name: MY_POD_NAME    valueFrom:      fieldRef:        fieldPath: metadata.name

There's no way to inject this data into a file without using something like an init container or an entrypoint script. The mechanisms Kubernetes has to inject files (for example, mounting a ConfigMap in a container) only inject fixed file content, and it will always be identical across all replicas.

If you specifically need the names to be in the sequential order you propose, or you need a name to be reused to recover storage, a StatefulSet will generate the pod names exactly like that (it also can automatically allocate storage, and starts the pods in a specific order).

There's nothing in Helm that would let you have a different configuration per replica. Its templating will help you construct the names and contents of the StatefulSet/Service/ConfigMap/... objects, but once you've created those, the Kubernetes controllers that create the individual Pods still work the same way, and still create some number of mostly-identical Pods with the same behavior.