zoukankan      html  css  js  c++  java
  • 使用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"
  • 相关阅读:
    认证功能装饰器
    装饰器升级版
    装饰器
    闭包函数
    名称空间与作用域
    嵌套函数
    函数对象
    命名关键字参数
    函数单数的使用
    函数的定义与调用
  • 原文地址:https://www.cnblogs.com/fengjian2016/p/10058369.html
Copyright © 2011-2022 走看看