I have a statefulset with an init container which creates openshift objects upon scaling. I need to pass it the replicas number from the same yaml definition. However the replicas filed doesn't seem to be working with fieldRef. Is there another way to do it?
If you launch the statefulset with the following key set
you can run
curl \ https://kubernetes/apis/apps/v1/namespaces/<NAMESPACE>/statefulsets/<STATEFULSET> \ -k -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \ | jq '.spec.replicas'
to extract the replica count. This, of course, relies on the service account (myserviceaccount in this example) to have appropriate permissions to actually query the k8s API for this information, as well as having curl and jq available in the container.
You could then setup some kind of background job in the container to regularly make this request and update an env var or file or whatever.
Define the number of replicas in the
values.yaml and pass it anywhere in resources (statefulset)
Update 1: You can neither have a dynamic environment variable nor refer to the replicas field in STS. So the only way to get an updated count of STS in each pod is to redeploy with the new value of replicas in
According to this link, you can mount a secret now to each pod and stay up to date about replicas count.
I suggest you try to pass this information as an update to the statefulset.
There are two ways either increase the number in your DeploymentConfig directly or use
oc scale statefulset <name_of_statfulset> --replicas=2
apiVersion: apps.openshift.io/v1 kind: DeploymentConfig metadata: labels: app: jekyll name: jekyll namespace: test spec: replicas: 1 <----------- here increase the number