云容器引擎 CCE-使用CoreDNS实现自定义域名解析:修改CoreDNS Hosts配置
修改CoreDNS Hosts配置
在CoreDNS中修改hosts后,可以不用单独在每个Pod中配置hosts添加解析记录。
- 登录CCE控制台,单击集群名称进入集群。
- 在左侧导航栏中选择“插件中心”,在CoreDNS下单击“编辑”,进入插件详情页。
- 在“参数配置”下编辑高级配置,在plugins字段添加以下内容。
{ "configBlock": "192.168.1.1 www.example.com\nfallthrough", "name": "hosts" }
此处配置不能遗漏fallthrough字段,fallthrough表示当在hosts找不到要解析的 域名 时,会将解析任务传递给CoreDNS的下一个插件。如果不写fallthrough的话,任务就此结束,不会继续解析,会导致集群内部域名解析失败的情况。
hosts的详细配置请参见https://coredns.io/plugins/hosts/。
图2 修改CoreDNS Hosts配置 - 单击“确定”完成配置更新。
- 在左侧导航栏中选择“配置与密钥”,在“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 }