CoreDNS 通常部署在中心节点。在边缘托管服务下,边缘节点与管控面机器网络不通,导致 Pod 内 DNS 无法使用。本文内容将指导您配置边缘节点的 CoreDNS。
已通过 kubectl 连接 Kubernetes 集群。
可以通过以下命令获取到当前的 Service 的 CIDR。k8s 默认的 CoreDNS 使用的是第 10 个,我们可以使用第 11 个。
kubectl get cm -n kube-system kubeadm-config -o yaml | grep serviceSubnet
例如:Service 的 CIDR 为 172.25.***.***/17
区间范围, 我们可以选择 172.25.***.11
作为边缘 DNS Service 的 IP。
CLUSTER_DNS_IP="172.25.***.11" # 边缘 DNS Service IP kubectl apply -f - <<EOF apiVersion: v1 kind: Service metadata: labels: k8s-app: kube-dns-edge kubernetes.io/cluster-service: "true" kubernetes.io/name: KubeDNS name: kube-dns-edge namespace: kube-system spec: clusterIP: ${CLUSTER_DNS_IP} ports: - name: dns port: 53 protocol: UDP targetPort: 53 - name: dns-tcp port: 53 protocol: TCP targetPort: 53 - name: metrics port: 9153 protocol: TCP targetPort: 9153 selector: k8s-app: kube-dns-edge sessionAffinity: None internalTrafficPolicy: Local type: ClusterIP --- apiVersion: apps/v1 kind: DaemonSet metadata: name: coredns namespace: kube-system labels: k8s-app: kube-dns-edge spec: selector: matchLabels: k8s-app: kube-dns-edge template: metadata: labels: k8s-app: kube-dns-edge spec: volumes: - name: config-volume configMap: name: coredns items: - key: Corefile path: Corefile defaultMode: 420 containers: - name: coredns image: $(kubectl get deployment -n kube-system coredns -o jsonpath="{$.spec.template.spec.containers[0].image}") args: - '-conf' - /etc/coredns/Corefile ports: - name: dns containerPort: 53 protocol: UDP - name: dns-tcp containerPort: 53 protocol: TCP - name: metrics containerPort: 9153 protocol: TCP resources: limits: memory: 2000Mi requests: cpu: 100m memory: 200Mi volumeMounts: - name: config-volume readOnly: true mountPath: /etc/coredns livenessProbe: httpGet: path: /health port: 8080 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 periodSeconds: 10 successThreshold: 1 failureThreshold: 5 readinessProbe: httpGet: path: /ready port: 8181 scheme: HTTP timeoutSeconds: 1 periodSeconds: 10 successThreshold: 1 failureThreshold: 3 terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: IfNotPresent securityContext: capabilities: add: - NET_BIND_SERVICE drop: - all readOnlyRootFilesystem: true allowPrivilegeEscalation: false restartPolicy: Always terminationGracePeriodSeconds: 30 dnsPolicy: Default nodeSelector: node.kubernetes.io/instance-type: edge-node serviceAccountName: coredns serviceAccount: coredns securityContext: {} schedulerName: default-scheduler tolerations: - key: CriticalAddonsOnly operator: Exists - key: node-role.kubernetes.io/master effect: NoSchedule - key: node-role.kubernetes.io/control-plane effect: NoSchedule - key: vei.bytedance.com/edge-node operator: Exists effect: NoSchedule updateStrategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 revisionHistoryLimit: 10 EOF
sudo systemctl restart kubelet