如何知道 CoreDNS 在 kubernetes pod 中生效

how to know the CoreDNS take effect in kubernetes pod

我正在部署 coredns(运行 在 node-01 中):

{
  "kind": "Deployment",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "coredns",
    "namespace": "kube-system",
    "selfLink": "/apis/extensions/v1beta1/namespaces/kube-system/deployments/coredns",
    "uid": "5d470d90-6cdf-4ef1-be00-6774d70fcb54",
    "resourceVersion": "14708222",
    "generation": 18,
    "creationTimestamp": "2019-09-22T06:28:28Z",
    "labels": {
      "addonmanager.kubernetes.io/mode": "Reconcile",
      "k8s-app": "kube-dns",
      "kubernetes.io/cluster-service": "true",
      "kubernetes.io/name": "CoreDNS"
    },
    "annotations": {
      "deployment.kubernetes.io/revision": "6"
    }
  },
  "spec": {
    "replicas": 1,
    "selector": {
      "matchLabels": {
        "k8s-app": "kube-dns"
      }
    },
    "template": {
      "metadata": {
        "creationTimestamp": null,
        "labels": {
          "k8s-app": "kube-dns"
        },
        "annotations": {
          "seccomp.security.alpha.kubernetes.io/pod": "docker/default"
        }
      },
      "spec": {
        "volumes": [
          {
            "name": "config-volume",
            "configMap": {
              "name": "coredns",
              "items": [
                {
                  "key": "Corefile",
                  "path": "Corefile"
                }
              ],
              "defaultMode": 420
            }
          }
        ],
        "containers": [
          {
            "name": "coredns",
            "image": "gcr.azk8s.cn/google-containers/coredns:1.3.1",
            "args": [
              "-conf",
              "/etc/coredns/Corefile"
            ],
            "ports": [
              {
                "name": "dns",
                "containerPort": 53,
                "protocol": "UDP"
              },
              {
                "name": "dns-tcp",
                "containerPort": 53,
                "protocol": "TCP"
              },
              {
                "name": "metrics",
                "containerPort": 9153,
                "protocol": "TCP"
              }
            ],
            "resources": {
              "limits": {
                "memory": "70Mi"
              },
              "requests": {
                "cpu": "100m",
                "memory": "70Mi"
              }
            },
            "volumeMounts": [
              {
                "name": "config-volume",
                "readOnly": true,
                "mountPath": "/etc/coredns"
              }
            ],
            "livenessProbe": {
              "httpGet": {
                "path": "/health",
                "port": 8080,
                "scheme": "HTTP"
              },
              "initialDelaySeconds": 60,
              "timeoutSeconds": 5,
              "periodSeconds": 10,
              "successThreshold": 1,
              "failureThreshold": 5
            },
            "readinessProbe": {
              "httpGet": {
                "path": "/health",
                "port": 8080,
                "scheme": "HTTP"
              },
              "timeoutSeconds": 1,
              "periodSeconds": 10,
              "successThreshold": 1,
              "failureThreshold": 3
            },
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "IfNotPresent",
            "securityContext": {
              "capabilities": {
                "add": [
                  "NET_BIND_SERVICE"
                ],
                "drop": [
                  "all"
                ]
              },
              "readOnlyRootFilesystem": true,
              "allowPrivilegeEscalation": false
            }
          }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "Default",
        "nodeSelector": {
          "beta.kubernetes.io/os": "linux"
        },
        "serviceAccountName": "coredns",
        "serviceAccount": "coredns",
        "securityContext": {},
        "schedulerName": "default-scheduler",
        "tolerations": [
          {
            "key": "CriticalAddonsOnly",
            "operator": "Exists"
          }
        ],
        "priorityClassName": "system-cluster-critical"
      }
    },
    "strategy": {
      "type": "RollingUpdate",
      "rollingUpdate": {
        "maxUnavailable": 1,
        "maxSurge": "25%"
      }
    },
    "revisionHistoryLimit": 10,
    "progressDeadlineSeconds": 600
  },
  "status": {
    "observedGeneration": 18,
    "replicas": 1,
    "updatedReplicas": 1,
    "readyReplicas": 1,
    "availableReplicas": 1,
    "conditions": [
      {
        "type": "Available",
        "status": "True",
        "lastUpdateTime": "2019-09-22T06:28:28Z",
        "lastTransitionTime": "2019-09-22T06:28:28Z",
        "reason": "MinimumReplicasAvailable",
        "message": "Deployment has minimum availability."
      },
      {
        "type": "Progressing",
        "status": "True",
        "lastUpdateTime": "2020-02-12T14:54:06Z",
        "lastTransitionTime": "2020-01-23T16:14:05Z",
        "reason": "NewReplicaSetAvailable",
        "message": "ReplicaSet \"coredns-89764d78c\" has successfully progressed."
      }
    ],
    "collisionCount": 1
  }
}

当我从 pods(node-01 中的 运行)ping 域时,它失败了:

# access external domain
/ # ping baidu.com
ping: bad address 'baidu.com'

# access oneself
/ # ping eureka-0
PING eureka-0 (172.30.208.2): 56 data bytes
64 bytes from 172.30.208.2: seq=0 ttl=64 time=0.054 ms

# access other pod
/ # ping zuul-service
ping: bad address 'zuul-service'

我想在 node-01 的 pod 中安装 curl:

/ # apk add curl
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.9/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.b89edf6e.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.9/community: temporary error (try again later)
WARNING: Ignoring APKINDEX.737f7e01.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
  curl (missing):
    required by: world[curl]

当我在 Node-03 中执行这个命令时,它起作用了fine.what我应该怎么做才能找出哪里出了问题?

[root@ops001 ~]# kubectl get pods --namespace=kube-system -l k8s-app=kube-dns
NAME                      READY   STATUS    RESTARTS   AGE
coredns-89764d78c-zmz27   1/1     Running   0          90m

这是 kubernetes 版本:

 [root@ops001 ~]# kubectl get nodes -o wide
NAME            STATUS   ROLES    AGE    VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION              CONTAINER-RUNTIME
azshara-k8s01   Ready    <none>   144d   v1.15.2   172.19.104.231   <none>        CentOS Linux 7 (Core)   3.10.0-957.5.1.el7.x86_64   docker://19.3.1
azshara-k8s02   Ready    <none>   144d   v1.15.2   172.19.104.230   <none>        CentOS Linux 7 (Core)   3.10.0-957.5.1.el7.x86_64   docker://18.9.6
azshara-k8s03   Ready    <none>   144d   v1.15.2   172.19.150.82    <none>        CentOS Linux 7 (Core)   3.10.0-957.5.1.el7.x86_64   docker://18.9.6

如我所见,您正在为 docker 容器使用 openjdk:8-jre-alpine,因此:

使用此命令行进行安装:

RUN apk update 首先或

删除缓存:

RUN rm -rf /var/cache/apk/* && \
    rm -rf /tmp/*

RUN apk --no-cache add curl 替换为 apk add curl