状态集和无头服务中的Pod无法获得正确的dns记录

时间:2019-05-24 15:26:24

标签: kubernetes

信息:

  • Kubernetes版本:1.14.1
  • 云:Azure(不是AKS)
  • DNS:CoreDNS
  • 部署者:Kubespray
  • 容器:已容器
  • 3个工作节点

说明

我有这个状态集:

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: busy
spec:
  serviceName: busy
  selector:
    matchLabels:
      app: busy
  replicas: 3
  template:
    metadata:
      name: busy
      labels:
        app: busy
    spec:
      containers:
        - name: busy
          image: busybox:1.28
          imagePullPolicy: IfNotPresent
          command:
            - sleep
            - "3600"
      restartPolicy: Always

这项无头的服务:

---
kind: Service
apiVersion: v1
metadata:
  name: busy-headless
spec:
  clusterIP: None
  publishNotReadyAddresses: true
  selector:
    app: busy

有状态集创建3个Pod(忙-{1,2,3})。根据{{​​3}},每个吊舱都应有一个busy-{1,2,3}.busy-headless.default.svc.cluster.local之类的DNS记录。

问题

当我尝试从busy-headless.default.svc.cluster.local解析与记录busy-0关联的DNS条目时,我得到

17:00 $ kubectl exec -ti busy-0 -- nslookup busy-headless.default.svc.cluster.local
Server:    10.233.0.3
Address 1: 10.233.0.3 coredns.kube-system.svc.cluster.local

Name:      busy-headless.default.svc.cluster.local
Address 1: 10.233.67.10 10-233-67-10.busy-headless.default.svc.cluster.local
Address 2: 10.233.68.27 10-233-68-27.busy-headless.default.svc.cluster.local
Address 3: 10.233.68.26 10-233-68-26.busy-headless.default.svc.cluster.local
Address 4: 10.233.69.11 busy-0.busy.default.svc.cluster.local

该命令从busy-1返回busy-1.busy.default.svc.cluster.local的{​​{1}}和busy-1返回10-233-69-11.busy-headless.default.svc.cluster.local

busy-0上的nslookup返回错误。

可能是什么问题?

谢谢!

1 个答案:

答案 0 :(得分:1)

在您的StatefulSet清单中尝试指定:

serviceName: busy-headless