Kubernetes 中不同服务之间可以通过 “service-name” 域名来相互访问,这是通过集群中的 CoreDNS 组件来完成域名解析工作的。但当我们想在 Pod 上增加一些域名解析时,可以通过 Pod 的 spec.hostAliases 字段往 /etc/hosts 文件中添加域名解析(集群需 1.7.x 及以上版)。
    image.png
    它大致等同于以下的 Pod 声明:

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: test
    5. spec:
    6. hostAliases:
    7. – ip: "10.1.2.2"
    8. hostnames:
    9. – "mc.local"
    10. – "rabbitmq.local"
    11. containers:
    12. – name: cathosts
    13. image: busybox
    14. ...