I have a statefulset and I need to know what is the current replica count from inside the pod. To do so, I tried:
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sample-mariadb
  namespace: demo
spec:
  replicas: 3
  template:
    spec:
      containers:
      - env:
        - name: REPLICAS
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.replicas
and got this error:
Warning FailedCreate 4m15s (x17 over 9m43s) statefulset-controller create Pod sample-mariadb-0 in StatefulSet sample-mariadb failed error: Pod "sample-mariadb-0" is invalid: spec.containers[1].env[3].valueFrom.fieldRef.fieldPath: Invalid value: "spec.replicas": error converting fieldPath: field label not supported: spec.replicas
How can I get current replica count from inside the pod?
You can only send the fields that are part of Pod specification. The spec.replicas field is part of StatefulSet specification not the underlying pod's. The template part of a StatefulSet is the pod specification. Hence, you are getting this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With