静态配置

通过 hostAliases 配置容器内的 Hosts 文件

1
2
3
4
5
hostAliases:
- hostnames:
- "sss"
- "aaa"
ip: 127.0.0.1

动态配置

通过环境变量在 command 中追加到 /etc/hosts

1
2
3
4
5
6
7
8
9
10
# 注入环境变量
envFrom:
- configMapRef:
name: sopei-biz-configmap
# 读取环境变量并追加到 /etc/hosts
command: ["/bin/sh", "-c"]
args:
- |
echo gateway-orange-sopei.sopei-biz.svc.cluster.local $web_domain >> /etc/hosts
node app.js