【问题标题】:Unable to resolve Kubernetes service names inside containers with the hostNetwork无法使用 hostNetwork 解析容器内的 Kubernetes 服务名称
【发布时间】:2020-11-10 14:13:58
【问题描述】:

使用hostNetwork时无法使用Kubernetes内部DNS:

/ test# nslookup echo
Server:    10.96.0.10
Address 1: 10.96.0.10

nslookup: can't resolve 'echo'

没有hostNetwork

/ test# nslookup echo
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      echo
Address 1: 10.98.232.198 echo.default.svc.cluster.local

裸机上的 Kubernetes 1.18.5 未升级(全新安装)。

完整配置:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: test
  labels:
    app: test

spec:
  selector:
    matchLabels:
      app: test

  template:
    metadata:
      labels:
        app: test

    spec:
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet

      containers:
      - image: busybox:1.28
        command:
          - sleep
          - "3600"
        imagePullPolicy: IfNotPresent
        name: busybox

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: echo
  template:
    metadata:
      labels:
        app: echo
    spec:
      containers:
        - name: echo
          image: jmalloc/echo-server
          ports:
            - name: http-port
              containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: echo
spec:
  ports:
    - name: http-port
      port: 80
      targetPort: http-port
      protocol: TCP
  selector:
    app: echo

【问题讨论】:

    标签: kubernetes kube-dns


    【解决方案1】:

    全新安装的 Kubernetes 1.19.0 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 2016-04-06
      相关资源
      最近更新 更多