kubernetes容器(rancher)利用HostAliases添加hosts地址解析

    技术2023-05-20  65

    在容器pod内,如果直接将域名记录到容器镜像的/etc/hosts文件是不行的,会是ip id这种形式,在1.7.x以及以上版本可以利用HostAliases来进行配置。 1、yaml配置:

    hostAliases: - ip: "11.111.21.65" hostnames: - "yw01-01" - ip: "11.111.21.66" hostnames: - "yw02-01"

    2、rancher配置: 在显示高级选项,找到网络,然后添加别名

    注意:rancher里面这个主机名不能使用下划线,要使用标准域名。

    3、其它添加hosts方式: yaml:CMD里面加 echo "xxxxxxxxxx" >> /etc/hosts ,但是容器里面的启动命令就要挪到外面来写 entrypoint等

    Processed: 0.013, SQL: 9