【问题标题】:how to set cluster dns to using coredns如何将集群 dns 设置为使用 coredns
【发布时间】:2020-05-31 08:39:19
【问题描述】:

我在kubernetes集群中部署了coredns,但是slave节点中的mysql pod(ip:10.244.8.43)没有使用coredns ip作为name server,我登录mysql pods并找到nameserver:

root@apollo-mysql-85fd475fc9-sjfhg:/# cat /etc/resolv.conf 
nameserver 10.96.0.10
search sre.svc.cluster.local svc.cluster.local cluster.local
options ndots:5

但是 coredns (v1.6.7) pod 的 ip 是:10.244.6.34,问题出在哪里?我应该怎么做才能使 coredns 对我的集群 pod 起作用?这是我的 pod 定义:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: apollo-mysql
  namespace: sre
  selfLink: /apis/apps/v1/namespaces/sre/deployments/apollo-mysql
  uid: b7a2f852-894d-4686-816c-21737535dbea
  resourceVersion: '498210'
  generation: 42
  creationTimestamp: '2020-05-30T11:27:09Z'
  annotations:
    deployment.kubernetes.io/revision: '4'
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"apollo-mysql","namespace":"sre"},"spec":{"selector":{"matchLabels":{"app":"apollo-mysql"}},"strategy":{"type":"Recreate"},"template":{"metadata":{"labels":{"app":"apollo-mysql"}},"spec":{"containers":[{"env":[{"name":"MYSQL_ROOT_PASSWORD","value":"gl4LucnXwLeLwAd29QqJn4"}],"image":"mysql:5.7","name":"mysql","ports":[{"containerPort":3306,"name":"mysql"}],"volumeMounts":[{"mountPath":"/var/lib/mysql","name":"apollo-mysql-persistent-storage"}]}],"volumes":[{"name":"apollo-mysql-persistent-storage","persistentVolumeClaim":{"claimName":"apollo-mysql-pv-claim"}}]}}}}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apollo-mysql
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: apollo-mysql
    spec:
      volumes:
        - name: apollo-mysql-persistent-storage
          persistentVolumeClaim:
            claimName: apollo-mysql-pv-claim
      containers:
        - name: mysql
          image: 'mysql:5.7'
          ports:
            - name: mysql
              containerPort: 3306
              protocol: TCP
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: gl4LucnXwLeLwAd29QqJn4
          resources: {}
          volumeMounts:
            - name: apollo-mysql-persistent-storage
              mountPath: /var/lib/mysql
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
  strategy:
    type: Recreate
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
status:
  observedGeneration: 42
  replicas: 1
  updatedReplicas: 1
  readyReplicas: 1
  availableReplicas: 1
  conditions:
    - type: Progressing
      status: 'True'
      lastUpdateTime: '2020-05-31T03:34:11Z'
      lastTransitionTime: '2020-05-30T11:38:19Z'
      reason: NewReplicaSetAvailable
      message: ReplicaSet "apollo-mysql-5f5c49c448" has successfully progressed.
    - type: Available
      status: 'True'
      lastUpdateTime: '2020-05-31T08:34:56Z'
      lastTransitionTime: '2020-05-31T08:34:56Z'
      reason: MinimumReplicasAvailable
      message: Deployment has minimum availability.

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    10.96.0.10 通常用作kube-dns 服务的 IP,该服务由coredns pod 提供。

    $ kubectl describe svc kube-dns -n kube-system
    Name:              kube-dns
    ...
    Type:              ClusterIP
    IP:                10.96.0.10
    Port:              dns  53/UDP
    TargetPort:        53/UDP
    Endpoints:         192.168.150.144:53,192.168.24.204:53
    ...
    

    所以我认为您的 coredns 正在被使用。检查 core-dns pod 上的 IP 以确保 IP 排列整齐:

    $ kubectl describe pod -n kube-system coredns-....-.... | grep IP
    IP:                   192.168.150.144
    

    请注意,在我的例子中,192.168.150.144 是 coredns pod 的 pod IP,它列在服务端点中。

    【讨论】:

      【解决方案2】:

      当我们在 Kubernetes 上启动 pod 时,Kubelet 会将 kube-dns 服务 IP(不是 pod IP)写入容器的 /etc/resolv.conf 文件中。

      kubectl get svc -n kube-system
      NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
      kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   29d
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-21
        • 1970-01-01
        • 2019-07-06
        • 1970-01-01
        • 2016-01-28
        相关资源
        最近更新 更多