Kubernetes PetSet DNS not working

I have a PetSet Kubernetes named == elasticsearchand serviceName == es. It creates containers and, as expected, they have names like elasticsearch-0and elasticsearch-1. However, DNS does not seem to work. elasticsearch-0.esdoes not allow (and does not elasticsearch-0.default, etc.). If you look at the generated srv entries, they seem random rather than predictable:

# nslookup -type=srv elasticsearch
Server:        10.1.0.2
Address:    10.1.0.2#53

elasticsearch.default.svc.cluster.local    service = 10 100 0 9627d60e.elasticsearch.default.svc.cluster.local.

Does anyone have any ideas?


More details

Here's the actual definition of PetSet and the service:

---
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch
  labels:
    app: elasticsearch
spec:
  ports:
  - name: rest
    port: 9200
  - name: native
    port: 9300
  clusterIP: None
  selector:
    app: elasticsearch
---
apiVersion: apps/v1alpha1
kind: PetSet
metadata:
  name: elasticsearch
spec:
  serviceName: "es"
  replicas: 2
  template:
    metadata:
      labels:
        app: elasticsearch
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      terminationGracePeriodSeconds: 0
      containers:
      - name: elasticsearch
        image: 672129611065.dkr.ecr.us-west-2.amazonaws.com/elasticsearch:v1
        ports:
          - containerPort: 9200
          - containerPort: 9300
        volumeMounts:
        - name: es-data
          mountPath: /usr/share/elasticsearch/data
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: ES_CLUSTER_NAME
            value: EsEvents
  volumeClaimTemplates:
  - metadata:
      name: es-data
      annotations:
        volume.alpha.kubernetes.io/storage-class: anything
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 10Gi
+4
source share
1 answer

This was a question when I read the documentation incorrectly. The docs say:

. , , . , , : $( ). $(Namespace).svc.cluster.local, "cluster.local" - . , DNS, : $(petname). $( ), serviceName Pet Set.

, serviceDomain " ", , . , serviceDomain , . , - DNS- .

+6

Source: https://habr.com/ru/post/1650942/


All Articles