Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Kubernetes StatefulSet error – serviceName environment variable doesn't exist

I’m supposed to make a StatefulSet with a Headless Service but when I make the Headless Service and create the StatefulSet only one pod gets made but with Error status and I get this error when trying to use kubectl log:

serviceName environment variable doesn’t exist! Fix your specification.

Here is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

apiVersion: v1
kind: Service
metadata:
  name: svc-hl-xyz
spec:
  clusterIP: None
  selector:
    app: svc-hl-xyz
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sts-xyz
spec:
  replicas: 3
  serviceName: "svc-hl-xyz"
  selector:
    matchLabels:
      app: svc-hl-xyz
  template:
    metadata:
      labels:
        app: svc-hl-xyz
    spec:
      containers:
        - name: ctr-sts-xyz
          image: quay.io/myafk/interactive:stable
          command: ["interactive", "workloads","-t=first"]

My specification seems to follow the Kubernetes documentation for StatefulSet so I’m not sure why it doesn’t work. All I can think of is that the command or the image I’m trying to use is causing this somehow.

>Solution :

The container logs (serviceName environment variable doesn't exist! Fix your specification.) tell you that the serviceName environment variable is missing.

Add it to the container spec in your statefulset:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: sts-xyz
spec:
  replicas: 3
  serviceName: "svc-hl-xyz"
  selector:
    matchLabels:
      app: svc-hl-xyz
  template:
    metadata:
      labels:
        app: svc-hl-xyz
    spec:
      containers:
        - name: ctr-sts-xyz
          image: quay.io/myafk/interactive:stable
          command: ["interactive", "workloads","-t=first"]
          env:
           - name: serviceName
             value: svc-hl-xyz

More information about env variables on Pods can be found in the docs

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading