coredns 排错记

发布时间:2019-08-06 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了coredns 排错记脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

核心链接

https://kubernetes.io/docs/ta...

CoredNS 安装

apiVersion: v1
kind: ServiceAccount
metadata:
  name: coredns
  namespace: kube-System
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: system:coredns
rules:
- apiGroups:
  - ""
  resources:
  - endpoints
  - services
  - pods
  - namespaces
  verbs:
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: system:coredns
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:coredns
subjects:
- kind: ServiceAccount
  name: coredns
  namespace: kube-system
---
apiVersion: v1
kind: configMap
metadata:
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
        LOG
        errors
        health
        kubernetes cluster.local 172.0.0.0/8 in-addr.arpa ip6.arpa {
          pods insecure
          upstream
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        Proxy . /etc/resolv.conf
        cache 30
        reload
    }
---
apiVersion: extensions/v1beta1
kind: deployment
metadata:
  name: coredns
  namespace: kube-system
  labels:
    k8s-app: coredns
    kubernetes.io/name: "CoreDNS"
sPEc:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  selector:
    matchLabels:
      k8s-app: coredns
  template:
    metadata:
      labels:
        k8s-app: coredns
    spec:
      serviceAccountName: coredns
      tolerations:
        - key: "CrITicalAddonsOnly"
          operator: "Exists"
      containers:
      - name: coredns
        image: hub.issll.COM/kubernetes/coredns:1.1.0
        imagePullpolicy: IfNotPResent
        args: [ "-conf", "/etc/coredns/Corefile" ]
        volumemounts:
        - name: config-volume
          mountPath: /etc/coredns
        ports:
        - containerPort: 53
          name: dns
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /health
            port: 8081
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
      dnsPolicy: Default
      volumes:
        - name: config-volume
          configMap:
            name: coredns
            items:
            - key: Corefile
              path: Corefile
---
apiVersion: v1
kind: Service
metadata:
  name: kube-dns
  namespace: kube-system
  labels:
    k8s-app: coredns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "CoreDNS"
spec:
  selector:
    k8s-app: coredns
  clusterIP: 172.21.0.2
  ports:
  - name: dns
    port: 53
    protocol: UDP
  - name: dns-tcp
    port: 53
    protocol: TCP

在master结点上执行

kubectl apply -f coredns.yaML

主要修改文件

nodes结点上的/etc/resolv.conf

    $ cat /etc/resolv.conf 
    # Generated by NetworkManager
    seArch default.svc.cluster.local middleware.svc.cluster.local svc.cluster.local cluster.local 
    nameserver 192.168.1.254

打印每个pods上的出错日志

for p in $(kubectl get pods --namespace=kube-system -l k8s-app=coredns -o name); do kubectl logs --namespace=kube-system $p; done 

用busybox 检验coredns解析效果

 kubectl exec -ti busybox -- nslookup redis-master

因为结点上的search 域的设定,等于

kubectl exec -ti busybox -- nslookup redis-master.middleware.svc.cluster.local

这里 redis-master 是布署在 middleware 命名空间下的一个pod

CoreDNS 已知 Bug

重新加载时,在启动新服务器实例之前停止运行状况处理程序。如果新服务器无法启动,则初始服务器实例仍然可用且仍然提供DNS查询,但Health处理程序保持关闭状态。在成功重新加载或完全重新启动CoreDNS之前,Health运行状况不会回复HTTP请求。

后记

在新 pod 创建后, CoreDNS 更新有问题, 需要解决

脚本宝典总结

以上是脚本宝典为你收集整理的coredns 排错记全部内容,希望文章能够帮你解决coredns 排错记所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。