在kubernetes1.2的时候,采用了skydns + kube2dns +etcd的方式来部署dns。而从1.3开始,则部署方式有了一点儿变化,将skydns和kube2dns封装到了一个容器镜像中,放弃了etcd,而将dns解析直接放入到了内存之中,同时引入了dnsmasq,进一步利用其缓存,具体的原理,请查阅相关文档。本篇文档,主要阐述新版的dns在kubernetes中的具体部署。
在Kubernetes的源码目录中,有个cluster/addons/dns目录,下面有几个与dns相关的文件,我们将其中的skydns-rc.yaml.sed以及skydns-svc.yaml.sed文件下载到本地,并去掉后缀。只是拷贝文件的话,可以通过https://rawgit.com这个地址加速,如下:
wget https://rawgit.com/kubernetes/kubernetes/release-1.5/cluster/addons/dns/skydns-rc.yaml.sed -O skydns-rc.yamlwget https://rawgit.com/kubernetes/kubernetes/release-1.5/cluster/addons/dns/skydns-svc.yaml.sed -O skydns-svc.yaml
下载下来的原文件是用于saltstack自动化安装的,我们手动处理的时候,需要进行相关修改。
修改skydns-rc.yaml内容如下:
# Copyright (the except - At some point, we need to rename all skydns-*.yaml.* files to kubedns-*.yaml.* cluster/addons/dns-horizontal-autoscaler/dns-horizontal- with this /---app: kube-/cluster-service: . In order to Addon Manager . Default is . Will be tuned real DNS horizontal auto-%-app: kube--app: kube-/critical-pod: /tolerations: -/library/kubedns-amd64: # clusters, set request = limit to keep this container category so the kubelet doesn/healthz-//readiness HTTP server once that initialDelaySeconds: - --domain=- --dns-port= - --config-map=kube-- --kube-master-url=http: # This should be set to v= only after the new p_w_picpath ( from - --v=-- containerPort: -- containerPort: -tcp-- containerPort: -/library/kube-dnsmasq-amd64:/healthz-- --cache-size= - --no-- --server=.#- --log-facility=- - containerPort: - containerPort: -- name: dnsmasq-/library/dnsmasq-metrics-amd64:/- --v= - --- containerPort: -/library/exechealthz-amd64: # limits are set higher than expected pending investigation on #- --cmd=nslookup kubernetes.default.svc.cluster.local . >/dev/ - --url=/healthz-- --cmd=nslookup kubernetes.default.svc.cluster.local .: >/dev/ - --url=/healthz-- --port= - --- containerPort:
修改skydns-svc.yaml内容如下:
# Copyright (the except - At some point, we need to rename all skydns-*.yaml.* files to kubedns-*.yaml.*---app: kube-/cluster-service: /name: -app: kube-.-- name: dns-
启动dns:
kubectl create -f skydns-rc.yaml kubectl create -f skydns-svc.yaml
修改各node节点上的/etc/kubernetes/kubelet配置文件,增加如下行:
KUBELET_ARGS="--cluster_dns=10.254.0.100 --cluster_domain=cluster.local"
重启各节点:
systemctl restart kubelet
添加一个busybox的pod用于测试,busybox.yaml内容如下:
apiVersion: v1 kind: Pod metadata: labels: name: busybox role: master name: busybox spec: containers: - name: busybox p_w_picpath: myhub.fdccloud.com/library/busybox command: - sleep - "3600"
执行如下操作:
kubectl exec -it busybox shnslookup kubernetes nslookup kubernetes.default.cluster.local nslookup kubernetes.default.svc.cluster.local
如果能正常解析,则部署OK。