1. 程式人生 > >使用HostAliases 新增pod 的/etc/hosts

使用HostAliases 新增pod 的/etc/hosts

預設的pod 的/etc/hosts 無法自動資料

[[email protected] ~]# kubectl exec  smsservice-5c7ff5f74-bc969 -n testihospital cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1    localhost
::1    localhost ip6-localhost ip6-loopback
fe00::0    ip6-localnet
fe00::0    ip6-mcastprefix
fe00::1    ip6-allnodes
fe00::
2 ip6-allrouters 10.254.110.5 smsservice-5c7ff5f74-bc969

 

通過使用  k8s  HostAliases ,可以想 pod /etc/hosts 注入主機名對應關係

apiVersion: v1
kind: Pod
metadata:
  name: hostaliases-pod
spec:
  restartPolicy: Never
  hostAliases:
  - ip: "127.0.0.1"
    hostnames:
    - "foo.local"
    - "
bar.local" - ip: "10.1.2.3" hostnames: - "foo.remote" - "bar.remote" containers: - name: cat-hosts image: busybox command: - cat args: - "/etc/hosts"