????之前公司內(nèi)部的kubernetes集群,在對其他事業(yè)部提供服務的時候,因為服務偏多,所以從nodePort方式改為了ingress暴露服務。使用xip.io這個公網(wǎng)解析來配置域名,但是由于在域名解析的過程中需要訪問該網(wǎng)站,解析速度較慢,因此采用了coredns來解決此問題,代替xip.io來解析kubernetes的ingress服務。
? ? 1、ingress-controller部署就不做陳述,直接講如何使用coredns來解析一個示例服務。
? ? 2、下載coredns:
wget https://github.com/coredns/coredns/releases/download/v1.3.0/coredns_1.3.0_linux_amd64.tgz
? ? 3、配置Corefile文件如下:
. {
? ? proxy . 223.5.5.5:53 {
? ? ? ? except example.com
? ? ? ? protocol dns
? ? }
? ? prometheus? ? # enable metrics
? ? errors stdout? # show errors
? ? log stdout? ? # show query logs
}
example.org {
? ? file /etc/coredns/zones/example.com
? ? prometheus? ? # enable metrics
? ? errors stdout? # show errors
? ? log stdout? ? # show query logs
}
4、配置example.com文件:
$ORIGIN example.com.
@? ? ? 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. (
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 2017042745 ; serial
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 7200? ? ? ; refresh (2 hours)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3600? ? ? ; retry (1 hour)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1209600? ? ; expire (2 weeks)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 3600? ? ? ; minimum (1 hour)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? )
? ? 3600 IN NS a.iana-servers.net.
? ? ? ? 3600 IN NS b.iana-servers.net.
*? ? ? IN A? ? 10.10.0.0
ps:10.10.0.0是ingress-controller的pod所在的node ip。
5、部署ingress服務:
示例服務:https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/complete-example
kubectl -f cafe*
6、coredns測試:
在測試機器上面編輯/etc/resove.conf
nameserver corednsIP
curl https://cafe.example.com/coffee --insecure
