部署 CoreDNS 服务(Alpha)
平台支持在内网中部署 CoreDNS 服务器,以便实现内网的域名解析功能。
前提条件
您须在当前集群中提前准备好 CoreDNS 的官方镜像,命令如下:
docker pull coredns/coredns:1.7.0
操作步骤
-
创建
corefile
文件并填充以下内容,其中hosts
字段中的值为您自定义的地址映射关系。# mkdir -p /etc/kubernetes/coredns # vi /etc/kubernetes/coredns/Corefile .:53 { errors health { lameduck 5s } ready hosts { 1.1.1.1 www.test.com 1.1.1.2 www.demo.com fallthrough } prometheus :9153 forward . /etc/resolv.conf { max_concurrent 1000 } cache 30 loop reload loadbalance }
-
使用 YAML 创建 Static Pod,文件如下:
提示: image 字段需替换前提条件已准备 CoreDNS 的基础镜像地址。
# vi /etc/kubernetes/manifests/acp-coredns.yaml apiVersion: v1 kind: Pod metadata: annotations: scheduler.alpha.kubernetes.io/critical-pod: "" labels: component: acp-coredns tier: control-plane name: acp-coredns namespace: kube-system spec: containers: - name: acp-coredns image: 192.168.39.10:60080/tkestack/coredns:1.7.0 imagePullPolicy: IfNotPresent args: - '-conf' - /etc/coredns/Corefile readinessProbe: failureThreshold: 3 httpGet: path: /ready port: 8181 scheme: HTTP periodSeconds: 10 successThreshold: 1 timeoutSeconds: 1 volumeMounts: - mountPath: /etc/coredns name: config-volume readOnly: false securityContext: runAsUser: 0 hostNetwork: true priorityClassName: system-cluster-critical volumes: - hostPath: path: /etc/kubernetes/coredns type: DirectoryOrCreate name: config-volume
注意:若为高可用集群,则需在所有 Master 节点上再次执行 1、2 步骤。
-
查看 Pod 状态并查看日志。
#kubectl get pod -n kube-system -l component=acp-coredns NAME READY STATUS RESTARTS AGE acp-coredns-192.168.39.21 1/1 Running 0 4m1s #kubectl logs -n kube-system -l component=acp-coredns .:53 [INFO] plugin/reload: Running configuration MD5 = 1e0203c87b5d1dfd4d0bc442f01f32c5 CoreDNS-1.7.0 linux/amd64, go1.14.4, f59c03d
-
验证配置是否成功。在某台主机上配置 DNS 服务器地址,并执行如下命令查看数据来源地址是否已被 DNS 解析。
#ping www.test.com PING www.test.com (1.1.1.1): 56 data bytes 64 bytes from 1.1.1.1: icmp_seq=0 ttl=50 time=272.503 ms