[TOC]
After DNS is installed, the pod can resolve the service through DNS to enable communication
Kubernetes version:
kubectl version
My current version is 1.9.0.
1, kubectl DNS installation 1.1 Download the configuration file on the official website
https://github.com/kubernetes/kubernetes具体路径是cluster/addons/dns/kube-dns 可能版本不一样,路径略有不同该路径下有三个相似的配置文件: kube-dns.yaml.base kube-dns.yaml.in kube-dns.yaml.sed
Here, we use the kube-dns.yaml.sed configuration file as a template;
1.2 You need to modify two of these properties
- $DNS _server_ip Specifies the IP of the k8s DNS, which is apiserver IP by default
- $DNS _domain, replace with cluster.local (consistent with kube-apiserver definition)
1.3 Specific modification commands, you can use the SED command
Copy the kube-dns.yaml.sed configuration file to one of the servers where the k8s cluster resides
- Renaming the configuration file
- Move kube-dns.yaml.sed Kube-dns.yaml
- Bulk Modify Properties
- Sed-i ' s/$DNS _server_ip/10.10.10.2/g ' Kube-dns.yaml
- Sed-i ' s/$DNS _domain/cluster.local/g ' Kube-dns.yaml
1.4 Starting the DNS service
kubectl create -f kube-dns.yaml
2 Testing DNS Services 2.1 creating a pod and service
Configuration file Curl.yaml
apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: curl namespace: kube-systemspec: replicas: 1 template: metadata: labels: app: curl spec: containers: - name: curl image: appropriate/curl command: ["sleep"] args: ["5000"]---apiVersion: v1kind: Servicemetadata: name: curl namespace: kube-system labels: app: curlspec: type: ClusterIP selector: app: curl ports: - port: 80 targetPort: 80 name: http protocol: TCP
2.2 Creating a DNS test tool pod
apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: tools-dns namespace: defaultspec: replicas: 1 template: metadata: labels: app: tools-dns spec: containers: - name: tools-dns image: tutum/dnsutils:latest command: ["sleep"] args: ["5000"]
2.3 View just created test pod, Tools-dns
2.4 After entering the container, use the following command to query
kubectl exec -it tools-dns-5665d49688-8jrnw /bin/bash
2.5 problems found in the test:
1、 如果发现镜像有问题的话,需要更新镜像, 如“k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.10” 改成“ index.tenxcloud.com/jimmy/k8s-dns-dnsmasq-nanny-amd64:1.14.1”将"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.10" 改成"index.tenxcloud.com/jimmy/k8s-dns-sidecar-amd64:1.14.1" 将" k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.10" 替换为"index.tenxcloud.com/jimmy/k8s-dns-kube-dns-amd64:1.14.12、如果发现"Liveness probe failed: Get http://172.17.97.2:10054/healthcheck/kubedns: dial tcp 172.17.97.2:10054: getsockopt: connection refused"问题,需要将"SRV"改成"A"
Reference documents:
79443852
Installation and deployment testing of DNS in Kubernetes