kube-dns,是有针对kube 1.3版本的petset新增的,如果使用petset,又想访问Hostname,那就需要使用kube-dns。
kube-dns命令在kube 1.3的源码包里有了,和kube-apiserver在同一目录下。
kube-dns在kube的功能已完胜skydns和kube2sky,在kube 1.3版本中,虽然没有找到确切的资料,但是测试的效果已然说明了:
①、相同点:kube-dns和skydns、kube2sky均可用解析kube内部和外部的DNS
②、不同点:测试发现skydns、kube2sky,无法解析petset的DNS(web-0.nginx和web-0.nginx.default.svc.perofu.com)
#skydns、kube2sky可以解析的 [root@web-0 /]# nslookup -type=srv nginx.default Server: 192.168.16.100 Address: 192.168.16.100#53 nginx.default.svc.perofu.com service = 10 50 0 c68268e8.nginx.default.svc.perofu.com. nginx.default.svc.perofu.com service = 10 50 0 4c018d1.nginx.default.svc.perofu.com. [root@web-0 /]# nslookup nginx.default.svc.perofu.com Server: 192.168.16.100 Address: 192.168.16.100#53 Name: nginx.default.svc.perofu.com Address: 172.22.3.2 Name: nginx.default.svc.perofu.com Address: 172.22.3.3 #skydns、kube2sky不可以解析的 [root@web-0 /]# nslookup web-1.nginx Server: 192.168.16.100 Address: 192.168.16.100#53
** server can't find web-1.nginx: NXDOMAIN |
1、配置etcd:
Skydns是需要配置这一步的,但是kube-dns不需要etcd
etcdctl mk /skydns/config '{"dns-addr": "www.perofu.com:53", "ttl": 3600,"domain": "perofu.com.", "nameservers": ["223.5.5.5:53", "114.114.114.114:53"]}' |
说明:
dns-addr: 指定skydns启动时的监听地址
ttl: 指域名的缓存的超时时间,单位秒
domain: 集群中的私有域名,这里如果不指定,默认为skydns.local. ,注意最后的一个点
nameservers:域名转发的dns列表,用来解析集群外部的域名
2、启动kube-dns:
nohup /root/kubernetes_version/kube-1.3.4/kube-dns --dns-port=53 --domain=perofu.com --kube-master-url="http://192.168.16.100:8080" & |
Kube-dns会启动三个端口:
①、tcp 53 :解析dns
②、udp 53 :解析dns
③、tcp 8081 :状态检测(http://127.0.0.1:8081//readiness)和dns记录(http://127.0.0.1:8081/cache)
3、配置kubelet:
在每个minion的kubelet启动时,加上--cluster-dns、 --cluster-domain参数,即可
nohup /usr/bin/kubelet --address=0.0.0.0 --port=10250 --hostname_override=192.168.16.240 --api_servers=http://192.168.16.100:8080 --cluster-dns=192.168.16.100 --cluster-domain=perofu.com --allow-privileged=true & |
4、验证(nslookup):
[root@web-0 /]# nslookup -type=srv nginx.default Server: 192.168.16.100 Address: 192.168.16.100#53 nginx.default.svc.perofu.com service = 10 50 0 c68268e8.nginx.default.svc.perofu.com. nginx.default.svc.perofu.com service = 10 50 0 4c018d1.nginx.default.svc.perofu.com. [root@web-0 /]# nslookup nginx.default.svc.perofu.com Server: 192.168.16.100 Address: 192.168.16.100#53
Name: nginx.default.svc.perofu.com Address: 172.22.3.2 Name: nginx.default.svc.perofu.com Address: 172.22.3.3
[root@web-1 /]# nslookup web-0.nginx Server: 192.168.16.100 Address: 192.168.16.100#53
Name: web-0.nginx.default.svc.perofu.com Address: 172.22.3.2
[root@web-1 /]# nslookup web-1.nginx Server: 192.168.16.100 Address: 192.168.16.100#53
Name: web-1.nginx.default.svc.perofu.com Address: 172.22.3.3
#解析外网 [root@web-1 /]# nslookup www.qq.com Server: 192.168.16.100 Address: 192.168.16.100#53
Non-authoritative answer: Name: www.qq.com Address: 59.37.96.63 Name: www.qq.com Address: 14.17.32.211 Name: www.qq.com Address: 14.17.42.40 |
[1288][root@www: kube-1.3_petset]# curl http://127.0.0.1:8081/readiness ok [1289][root@www: kube-1.3_petset]# curl http://127.0.0.1:8081/cache { "ChildNodes": { "com": { "ChildNodes": { "perofu": { "ChildNodes": { "svc": { "ChildNodes": { "default": { "ChildNodes": { "kubernetes": { "ChildNodes": { "_tcp": { "ChildNodes": { "_https": { "ChildNodes": {}, "Entries": { "3362356536323463": { "host": "kubernetes.default.svc.perofu.com.", "port": 443, "priority": 10, "weight": 10, "ttl": 30 } } } }, "Entries": {} } }, "Entries": { "3362356536323463": { "host": "10.1.0.1", "priority": 10, "weight": 10, "ttl": 30 } } }, "nginx": { "ChildNodes": { "_tcp": { "ChildNodes": { "_web": { "ChildNodes": {}, "Entries": { "web-0": { "host": "web-0.nginx.default.svc.perofu.com.", "port": 80, "priority": 10, "weight": 10, "ttl": 30 }, "web-1": { "host": "web-1.nginx.default.svc.perofu.com.", "port": 80, "priority": 10, "weight": 10, "ttl": 30 } } } }, "Entries": {} } }, "Entries": { "web-0": { "host": "172.22.3.2", "priority": 10, "weight": 10, "ttl": 30 }, "web-1": { "host": "172.22.3.3", "priority": 10, "weight": 10, "ttl": 30 } } } }, "Entries": {} } }, "Entries": {} } }, "Entries": {} } }, "Entries": {} } }, "Entries": {} } |