云容器引擎 CCE-合理配置CoreDNS:合理配置Host

时间:2024-04-03 08:02:33

合理配置Host

如果您需要为特定域名指定hosts,可以使用Hosts插件来配置。示例配置如下:

  1. 登录CCE控制台,单击集群名称进入集群。
  2. 在左侧导航栏中选择“插件中心”,在CoreDNS下单击“编辑”,进入插件详情页。
  3. “参数配置”下编辑高级配置,在plugins字段添加以下内容。

    {
      "configBlock": "192.168.1.1 www.example.com\nfallthrough",
      "name": "hosts"
    }

    此处配置不能遗漏fallthrough字段,fallthrough表示当在hosts找不到要解析的域名时,会将解析任务传递给CoreDNS的下一个插件。如果不写fallthrough的话,任务就此结束,不会继续解析,会导致集群内部域名解析失败的情况。

    hosts的详细配置请参见https://coredns.io/plugins/hosts/

  4. 单击“确定”完成配置更新。
  5. 在左侧导航栏中选择“配置与密钥”,在“kube-system”命名空间下,查看名为coredns的配置项数据,确认是否更新成功。

    对应Corefile内容如下:

    .:5353 {
        bind {$POD_IP}
        hosts {
          192.168.1.1 www.example.com
          fallthrough
        }
        cache 30
        errors
        health {$POD_IP}:8080
        kubernetes cluster.local in-addr.arpa ip6.arpa {
            pods insecure
            fallthrough in-addr.arpa ip6.arpa
        }
        loadbalance round_robin
        prometheus {$POD_IP}:9153
        forward . /etc/resolv.conf {
            policy random
        }
        reload
        ready {$POD_IP}:8081
    }

support.huaweicloud.com/bestpractice-cce/cce_bestpractice_0357.html