码迷,mamicode.com
首页 > Web开发 > 详细

向Kubernetes集群域名服务器中插入自定义的解析记录-coredns

时间:2020-07-26 16:05:35      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:loop   pod   edit   config   ping   app   elf   dns   解析   

向Kubernetes集群域名服务器中插入自定义的解析记录-coredns
注意:从Kubenretes 1.14开始,集群内部的域名服务器默认换成了coredns

找到kube-system命名空间的名称为coredns的configmap:
? kubectl get configmap coredns -n kube-system
NAME DATA AGE
coredns 1 9d

?
编辑这个configmap:

~ ? kubectl edit configmap coredns -n kube-system
编辑为以下内容(添加了hosts块):

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          upstream
          fallthrough in-addr.arpa ip6.arpa
          ttl 30
        }
        hosts {
            10.10.10.10 www.baidu.com
            10.10.10.11 www.baidu.cn      #添加记录
        }
        prometheus :9153
        forward . "/etc/resolv.conf"
        cache 30
        loop
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"Corefile":".:53 {\n    errors\n    health\n    kubernetes cluster.local in-addr.arpa ip6.arpa {\n      pods insecure\n      upstream\n      fallthrough in-addr.arpa ip6.arpa\n      ttl 30\n    }\n    prometheus :9153\n    forward . \"/etc/resolv.conf\"\n    cache 30\n    loop\n    reload\n    loadbalance\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"EnsureExists"},"name":"coredns","namespace":"kube-system"}}
  creationTimestamp: "2019-08-19T09:14:15Z"
  labels:
    addonmanager.kubernetes.io/mode: EnsureExists
  name: coredns
  namespace: kube-system
  resourceVersion: "3231349"
  selfLink: /api/v1/namespaces/kube-system/configmaps/coredns
  uid: b791c47f-c261-11e9-b426-525400116042

重启coredns:

~ ? kubectl scale deployment coredns -n kube-system --replicas=0
deployment.extensions/coredns scaled

~ ? kubectl scale deployment coredns -n kube-system --replicas=2
deployment.extensions/coredns scaled
测试,进入任意一个具有ping命令的pod中,ping自己插入的域名,能通就说明已经生效了。

向Kubernetes集群域名服务器中插入自定义的解析记录-coredns

标签:loop   pod   edit   config   ping   app   elf   dns   解析   

原文地址:https://blog.51cto.com/13534471/2513355

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!