通过HostAliases修改hosts文件

[root@master-1 nginx]# cat nginx-passport.yaml

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"

 

#查看运行结果

[root@master-1 ~]# kubectl logs -f hostaliases-pod

# 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

172.17.95.3     hostaliases-pod

 

# Entries added by HostAliases.

127.0.0.1       foo.local       bar.local

10.1.2.3        foo.remote      bar.remote

posted @ 2021-06-30 16:50  lpaxq  阅读(209)  评论(0编辑  收藏  举报