【问题标题】:Cannot reach bind dns in Kubernetes无法在 Kubernetes 中访问绑定 dns
【发布时间】:2020-04-26 06:59:20
【问题描述】:

我正在尝试使用 microK8S 在本地 Kubernetes 集群中安装 DNS 服务器,但我无法访问 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

当我 ssh 进入绑定 pod 时,它可以工作

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

怎么了?为什么我无法访问服务器?

【问题讨论】:

    标签: kubernetes dns bind microk8s


    【解决方案1】:

    服务资源spec.selector需要指定podspec.metadata.labels。
    所以我认为你需要更改yaml文件的Service资源。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-03
      • 2020-07-06
      • 2016-10-31
      • 1970-01-01
      相关资源
      最近更新 更多