本部分将部署 DNS 扩展,用于为集群内的应用提供服务发现。

DNS 扩展

部属 kube-dns 群集扩展:

  1. kubectl apply -f https://storage.googleapis.com/kubernetes-the-hard-way/coredns.yaml

输出为

  1. serviceaccount/coredns created
  2. clusterrole.rbac.authorization.k8s.io/system:coredns created
  3. clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
  4. configmap/coredns created
  5. deployment.extensions/coredns created
  6. service/kube-dns created

列出 kube-dns 部署的 Pod 列表:

  1. kubectl get pods -l k8s-app=kube-dns -n kube-system

输出为

  1. NAME READY STATUS RESTARTS AGE
  2. coredns-699f8ddd77-94qv9 1/1 Running 0 20s
  3. coredns-699f8ddd77-gtcgb 1/1 Running 0 20s

验证

建立一个 busybox 部署:

  1. kubectl run busybox --image=busybox --command -- sleep 3600

列出 busybox 部署的 Pod:

  1. kubectl get pods -l run=busybox

输出为

  1. NAME READY STATUS RESTARTS AGE
  2. busybox-2125412808-mt2vb 1/1 Running 0 15s

查询 busybox Pod 的全名:

  1. POD_NAME=$(kubectl get pods -l run=busybox -o jsonpath="{.items[0].metadata.name}")

busybox Pod 中查询 DNS:

  1. kubectl exec -ti $POD_NAME -- nslookup kubernetes

输出为

  1. Server: 10.32.0.10
  2. Address 1: 10.32.0.10 kube-dns.kube-system.svc.cluster.local
  3. Name: kubernetes
  4. Address 1: 10.32.0.1 kubernetes.default.svc.cluster.local

下一步:烟雾测试