Невозможно достичь привязки DNS в Kubernetes - PullRequest
0 голосов
/ 08 января 2020

Я пытаюсь установить DNS-сервер внутри локального кластера Kubernetes, используя microK8S, но не могу подключиться к DNS.

Здесь сценарий развертывания:

---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: bind
  labels:
    app: bind
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bind
  template:
    metadata:
      labels:
        app: bind
    spec:
      containers:
        - name: bind
          image: sameersbn/bind
          env:
            - name: ROOT_PASSWORD
              value: "toto"
          volumeMounts:
            - mountPath: /data
              name: data
          ports:
            - containerPort: 53
              protocol: UDP
            - containerPort: 53
              protocol: TCP
            - containerPort: 10000
      volumes:
        - name: data
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: bind-dns
  labels:
    name: bind-dns
spec:
  type: ClusterIP
  ports:
    - name: dns
      port: 53
      targetPort: 53
      protocol: UDP
    - name: dns-tcp
      port: 53
      protocol: TCP
      targetPort: 53
  selector:
    name: bind

служба предоставляется с помощью ip

bind-dns        LoadBalancer   10.152.183.144   <pending>     53/UDP,53/TCP     11m

Когда я sh ввязываю модуль, он работает

host www.google.com 0.0.0.0
Using domain server:
Name: 0.0.0.0
Address: 0.0.0.0#53
Aliases: 

www.google.com has address 172.217.13.132
www.google.com has IPv6 address 2607:f8b0:4020:805::2004

Но вне контейнера он не

host www.google.com 10.152.183.144
;; connection timed out; no servers could be reached

Что не так? Почему я не могу связаться с сервером?

1 Ответ

1 голос
/ 09 января 2020

Сервисный ресурс spec.selector необходимо указать pod spec.metadata.labels.
Так что я думаю, что вам нужно изменить сервисный ресурс файла yaml.

apiVersion: v1
kind: Service
metadata:
  name: bind-dns
  labels:
    name: bind-dns
spec:
  type: ClusterIP
  ports:
    - name: dns
      port: 53
      targetPort: 53
      protocol: UDP
    - name: dns-tcp
      port: 53
      protocol: TCP
      targetPort: 53
  selector:
    app: bind # changed
...