使用HostAliases 添加pod 的/etc/hosts

默认的pod 的/etc/hosts 无法自动数据

[root@master1 ~]# 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"

 

posted @ 2018-12-03 14:41  fengjian1585  阅读(792)  评论(0编辑  收藏  举报