kube-dns无法解析'kubernetes.default.svc.cluster.local'

时间:2017-03-01 07:47:01

标签: docker kubernetes kube-dns

使用kargo部署kubernetes集群后,我发现kubedns pod无法正常工作:

$ kcsys get pods -o wide

NAME          READY STATUS           RESTARTS AGE  IP           NODE
dnsmasq-alv8k 1/1   Running          2        1d   10.233.86.2  kubemaster
dnsmasq-c9y52 1/1   Running          2        1d   10.233.82.2  kubeminion1
dnsmasq-sjouh 1/1   Running          2        1d   10.233.76.6  kubeminion2
kubedns-hxaj7 2/3   CrashLoopBackOff 339      22h  10.233.76.3  kubeminion2

PS: kcsys kubectl --namespace=kube-system的别名

每个容器(kubedns,dnsmasq)的日志似乎没问题,除了healthz容器如下:

2017/03/01 07:24:32 Healthz probe error: Result of last exec: nslookup: can't resolve 'kubernetes.default.svc.cluster.local' error exit status 1

更新

kubedns rc description

apiVersion: v1
kind: ReplicationController
metadata:
  creationTimestamp: 2017-02-28T08:31:57Z
  generation: 1
  labels:
    k8s-app: kubedns
    kubernetes.io/cluster-service: "true"
    version: v19
  name: kubedns
  namespace: kube-system
  resourceVersion: "130982"
  selfLink: /api/v1/namespaces/kube-system/replicationcontrollers/kubedns
  uid: 5dc9f9f2-fd90-11e6-850d-005056a020b4
spec:
  replicas: 1
  selector:
    k8s-app: kubedns
    version: v19
  template:
    metadata:
      creationTimestamp: null
      labels:
        k8s-app: kubedns
        kubernetes.io/cluster-service: "true"
        version: v19
    spec:
      containers:
      - args:
        - --domain=cluster.local.
        - --dns-port=10053
        - --v=2
        image: gcr.io/google_containers/kubedns-amd64:1.9
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 5
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        name: kubedns
        ports:
        - containerPort: 10053
          name: dns-local
          protocol: UDP
        - containerPort: 10053
          name: dns-tcp-local
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /readiness
            port: 8081
            scheme: HTTP          
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        resources:
          limits:
            cpu: 100m
            memory: 170Mi
          requests:
            cpu: 70m
            memory: 70Mi
        terminationMessagePath: /dev/termination-log
      - args:
        - --log-facility=-
        - --cache-size=1000
        - --no-resolv
        - --server=127.0.0.1#10053
        image: gcr.io/google_containers/kube-dnsmasq-amd64:1.3
        imagePullPolicy: IfNotPresent
        name: dnsmasq
        ports:
        - containerPort: 53
          name: dns
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
        resources:
          limits:
            cpu: 100m
            memory: 170Mi
          requests:
            cpu: 70m
            memory: 70Mi
        terminationMessagePath: /dev/termination-log
      - args:
        - -cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 >/dev/null
          && nslookup kubernetes.default.svc.cluster.local 127.0.0.1:10053 >/dev/null
        - -port=8080
        - -quiet
        image: gcr.io/google_containers/exechealthz-amd64:1.1
        imagePullPolicy: IfNotPresent
        name: healthz
        ports:
        - containerPort: 8080
          protocol: TCP
        resources:
          limits:
            cpu: 10m
            memory: 50Mi
          requests:
            cpu: 10m
            memory: 50Mi
        terminationMessagePath: /dev/termination-log
      dnsPolicy: Default
      restartPolicy: Always
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  fullyLabeledReplicas: 1
  observedGeneration: 1
  replicas: 1`

kubedns svc说明:

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2017-02-28T08:31:58Z
  labels:
    k8s-app: kubedns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: kubedns
  name: kubedns
  namespace: kube-system
  resourceVersion: "10736"
  selfLink: /api/v1/namespaces/kube-system/services/kubedns
  uid: 5ed4dd78-fd90-11e6-850d-005056a020b4
spec:
  clusterIP: 10.233.0.3
  ports:
  - name: dns
    port: 53
    protocol: UDP
    targetPort: 53
  - name: dns-tcp
    port: 53
    protocol: TCP
    targetPort: 53
  selector:
    k8s-app: kubedns
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

我在kubedns容器中发现了一些错误:

1 reflector.go:199] pkg/dns/dns.go:145: Failed to list *api.Endpoints: Get https://10.233.0.1:443/api/v1/endpoints?resourceVersion=0: dial tcp 10.233.0.1:443: i/o timeout
1 reflector.go:199] pkg/dns/dns.go:148: Failed to list *api.Service: Get https://10.233.0.1:443/api/v1/services?resourceVersion=0: dial tcp 10.233.0.1:443: i/o timeout

更新2

  1. 在创建具有3个pod的主机名服务时由kube-proxy创建的iptables规则:
  2. enter image description here

      控制器管理器pod的
    1. 标志: enter image description here

    2. pods状态

    3. enter image description here

2 个答案:

答案 0 :(得分:1)

您可以查看ps auxf | grep dockerd的输出。

Kargo正在将设置iptables=false添加到docker守护程序中。据我所知,这导致容器到主机网络的问题,因为连接到10.233.0.1:443将遵循iptable规则,将请求转发到主节点之一' api服务器。

其他kubernetes服务将其网络绑定到主机,因此您不会遇到此问题。

我不确定这是否是根本问题,但是从docker守护程序设置中删除iptables=false修复了我们遇到的任何问题。默认情况下不会禁用此功能,并且不会因使用法兰绒等网络覆盖而禁用此功能。

删除docker守护程序的iptables选项可以从/etc/systemd/system/docker.service.d/docker-options.conf中完成,它应该是这样的:

[root@k8s-joy-g2eqd2 ~]# cat /etc/systemd/system/docker.service.d/docker-options.conf [Service] Environment="DOCKER_OPTS=--insecure-registry=10.233.0.0/18 --graph=/var/lib/docker --iptables=false"

更新后,您可以运行systemctl daemon-reload注册更改,然后systemctl restart docker

这将允许您测试这是否可以解决您的问题。一旦您确认这是修复,您可以覆盖kargo部署中的docker_options变量以排除该规则:

docker_options: "--insecure-registry=10.233.0.0/18 --graph=/var/lib/docker"

答案 1 :(得分:0)

根据您发布的错误,kubedns无法与API服务器通信:

dial tcp 10.233.0.1:443: i/o timeout

这可能意味着三件事:

未正确配置容器的网络结构

  • 查找您正在使用的网络解决方案的日志中的错误
  • 确保每个Docker守护程序都使用自己的IP范围
  • 验证容器网络是否与主机网络重叠

您的kube-proxy出现问题,使用kubernetes内部服务(10.233.0.1)时,网络流量未转发到API服务器

  • 检查节点上的kube-proxy日志(kubeminion {1,2}),如果您发现任何错误,请更新您的问题

如果您还看到身份验证错误:

kube-controller-manager无法生成有效的服务帐户令牌

  • 检查--service-account-private-key-file的{​​{1}}和--root-ca-file标记是否设置为有效密钥/证书并重新启动服务

  • 删除kube-controller-manager命名空间中的default-token-xxxx密码并重新创建kube-system部署