Kubernetes集群添加主机名解析

SuKai November 22, 2024

  1. 单个Pod添加主机别名
  2. CoreDNS添加主机名解析

单个Pod添加主机名别名

      dnsPolicy: ClusterFirst
      hostAliases:
      - hostnames:
        - jingxiang.oss-cn-lasa-xzns-d01-a.ops.ningsuan.com.cn
        - oss-cn-lasa-xzns-d01-a.ops.ningsuan.com.cn
        ip: 10.65.10.91
      initContainers:

NodeLocalDNS 169.254.25.10将DNS解析转发到CoreDNS 10.233.0.3

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: "2024-09-15T01:02:02Z"
  labels:
    addonmanager.kubernetes.io/mode: EnsureExists
  name: nodelocaldns
  namespace: kube-system
  resourceVersion: "55695455"
  uid: 8b2c7245-6563-4a5f-bb11-cbdc5bb9e17c
data:
  Corefile: |
    cluster.local:53 {
        errors
        cache {
            success 9984 30
            denial 9984 5
        }
        reload
        loop
        bind 169.254.25.10
        forward . 10.233.0.3 {
            force_tcp
        }
        prometheus :9253
        health 169.254.25.10:9254
    }
    in-addr.arpa:53 {
        errors
        cache 30
        reload
        loop
        bind 169.254.25.10
        forward . 10.233.0.3 {
            force_tcp
        }
        prometheus :9253
    }
    ip6.arpa:53 {
        errors
        cache 30
        reload
        loop
        bind 169.254.25.10
        forward . 10.233.0.3 {
            force_tcp
        }
        prometheus :9253
    }
    .:53 {
        errors
        cache 30
        reload
        loop
        bind 169.254.25.10
        forward . 10.233.0.3 {
            force_tcp
        }
        prometheus :9253
    }    

CoreDNS配置添加hosts主机名解析

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: "2024-09-15T01:01:58Z"
  labels:
    addonmanager.kubernetes.io/mode: EnsureExists
  name: coredns
  namespace: kube-system
  resourceVersion: "55644208"
  uid: 7e4fb70b-bac6-4c13-ad1a-8e9c0dbc0861
data:
  Corefile: |
    .:53 {
        errors
        health {
          lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        hosts {
          10.65.10.91 jingxiang.oss-cn-lasa-xzns-d01-a.ops.ningsuan.com.cn
          10.65.10.91 oss-cn-lasa-xzns-d01-a.ops.ningsuan.com.cn
          fallthrough
        }
        prometheus :9153
        forward . 114.114.114.114 {
          prefer_udp
          max_concurrent 1000
        }
        cache 30
        loop
        reload
        loadbalance
    }