k8s安装之DNS

xiunai 2019-10-27

DNS
kubeDns
wget https://storage.googleapis.com/kubernetes-release/release/v1.11.0/kubernetes-server-linux-amd64.tar.gz
tar -xzvf kubernetes-server-linux-amd64.tar.gz
cd kubernetes
tar -zxf kubernetes-src.tar.gz
cp cluster/addons/dns/kube-dns/kube-dns.yaml.sed ~/kube-dns/kubedns-service.yaml
修改image地址
#把文件中$DNS_SERVER_IP替换成10.254.0.2
sed -i ‘s/$DNS_SERVER_IP/10.254.0.2/g‘ ./kubedns-service.yaml
#把$DNS_DOMAIN替换成cluster.local
sed -i ‘s/$DNS_DOMAIN/cluster.local/g‘ ./kubedns-service.yaml

增加父系DNS
修改配置文件kubedns-service.yaml 

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-dns
  namespace: kube-system
  labels:
    addonmanager.kubernetes.io/mode: EnsureExists
data:
  stubDomains: | ##此处指定以test.duia.com结尾的域名使用10.0.0.55解析
    {"test.duia.com":["10.0.0.55"]}
  upstreamNameservers: | ##此处指定覆盖上级dns
    ["223.5.5.5"]

启动

kubectl create -f kubedns-service.yaml

验证

get pods --namespace="kube-system"

NAME                                    READY     STATUS    RESTARTS   AGE
kube-dns-8498694664-99gqr               3/3       Running   0          38m
kubernetes-dashboard-69db8c7745-hdhbg   1/1       Running   1          3h
测试

进入随意一个容器,可以Ping通外网地址

coreDns
配置文件各项目的含义
名称|含义
---|---
errors|错误会被记录到标准输出
health|可以通过http://localhost:8080/health查看健康状况
kubernetes|根据服务的IP响应DNS查询请求,kubeadm的Cluster Domain和Service CIDR默认为cluster.local和10.95.0.0/12,可以通过--service-dns-domain和--service-cidr参数配置。
prometheus|可以通过http://localhost:9153/metrics获取prometheus格式的监控数据
proxy|本地无法解析后,向上级地址进行查询,默认使用宿主机的 /etc/resolv.conf 配置
cache|缓存时间

[ ~]# kubectl -n kube-system get configmap coredns -o yaml
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
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  creationTimestamp: "2019-08-22T10:09:36Z"
  name: coredns
  namespace: kube-system
  resourceVersion: "181"
  selfLink: /api/v1/namespaces/kube-system/configmaps/coredns
  uid: bb1db052-35c7-4162-8fc6-7ff8fe164ae2

相关推荐

oLeiShen / 0评论 2020-05-26