kubernetes的服务发现有使用环境变量和DNS两种方式,本章节部署DNS插件来提供kubernetes的服务发现。
kubectl create -f https://raw.githubusercontent.com/chijiajian/k8sstudy/master/deployments/kube-dns.yaml
kubectl get pods --namespace=kube-system | grep kube-dns
输出
kube-dns-7797cb8758-66sz9 3/3 Running 0 9m
kube-dns-7797cb8758-z7zh5 3/3 Running 0 9m
跑一个dns tool的pod进行测试 kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools
dnstools# nslookup kubernetes
Server: 192.168.0.10
Address: 192.168.0.10#53
Non-authoritative answer:
Name: kubernetes.default.svc.cluster.local
Address: 192.168.0.1