2

I am configuring a statefulset deploying 2 Jira DataCenter nodes. The statefulset results in 2 pods. Everything seems fine until the 2 pods try to connect to eachother. They do this with their short hostname being jira-0 and jira-1.

The jira-1 pod reports UnknownHostException when connecting to jira-0. The hostname can not be resolved.

I read about adding a headless service which I didn't have yet. After adding that I can resolve the FQDN but still no luck for the short name.

Then I read this page: DNS for Services and Pods and added:

      dnsConfig:
        searches:
          - jira.default.svc.cluster.local

That solves my issue but I think it shouldn't be necessary to add this?

Some extra info:

  • Cluster on AKS with CoreDNS
  • Kubernetes v1.19.9
  • Network plugin: Kubenet
  • Network policy: none

My full yaml file:

apiVersion: v1
kind: Service
metadata:
  name: jira
  labels:
    app: jira
spec:
  clusterIP: None
  selector:
    app: jira
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: jira
spec:
  serviceName: jira
  replicas: 0
  selector:
    matchLabels:
      app: jira
  template:
    metadata:
      labels:
        app: jira
    spec:
      containers:
      - name: jira
        image: atlassian/jira-software:8.12.2-jdk11
        readinessProbe:
          httpGet:
            path: /jira/status
            port: 8080
          initialDelaySeconds: 120
          periodSeconds: 10
        livenessProbe:
          httpGet:
            path: /jira/
            port: 8080
          initialDelaySeconds: 600
          periodSeconds: 10
        envFrom:
          – configMapRef:
              name: jira-config
        ports:
        - containerPort: 8080
      dnsConfig:
        searches:
          - jira.default.svc.cluster.local
Jonas
  • 121,568
  • 97
  • 310
  • 388
Charlie
  • 521
  • 1
  • 4
  • 17

1 Answers1

1

That solves my issue but I think it shouldn't be necessary to add this?

From the StatefulSet documentation:

StatefulSets currently require a Headless Service to be responsible for the network identity of the Pods. You are responsible for creating this Service.

The example above will create three Pods named web-0,web-1,web-2. A StatefulSet can use a Headless Service to control the domain of its Pods.

The pod-identity is will be subdomain to the governing service, eg. in your case it will be e.g:

jira-0.jira.default.svc.cluster.local
jira-1.jira.default.svc.cluster.local
Jonas
  • 121,568
  • 97
  • 310
  • 388
  • Thanks for your answer but I was referring to the dnsConfig not the headless service – Charlie Apr 27 '21 at 16:00
  • Aha, should I create separate headless services for each pod in the statefulset? I only created 1 called jira as you can see at the top of the yaml – Charlie Apr 27 '21 at 17:22
  • 1
    Hmm that's far from ideal. Every time the replicas is increased a new service would have to be created. On https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/ only 1 headless service is used. But they don't mention dns resolution for the short hostname. So I guess the solution I'm using with dnsConfig is not that bad after all. – Charlie Apr 27 '21 at 18:34
  • You are right, I updated my answer. The pods will be subdomain to the main service. You should not need to manually add dns configs. – Jonas Apr 27 '21 at 18:59
  • Also beware the DNS caching documented on https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id – Jonas Apr 27 '21 at 19:02