Pods不通过ingress解析服务域名

Pods do not resolve the domain names of a service through ingress

我有一个问题,我的 pods 在 minikube 集群中无法通过域名看到服务。

到 运行 我的 minikube 我使用以下命令(运行ning on windows 10):
minikube start --vm-driver hyperv;
minikube addons enable kube-dns;
minikube addons enable ingress;

这是我的deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    run: hello-world
  name: hello-world
  namespace: default
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: hello-world
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: hello-world
    spec:
      containers:
      - image: karthequian/helloworld:latest
        imagePullPolicy: Always
        name: hello-world
        ports:
        - containerPort: 80
          protocol: TCP
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30

这是 service.yaml:

apiVersion: v1                                                             
kind: Service                                                              
metadata:                                                                  
  labels:                                                                  
    run: hello-world                                                       
  name: hello-world                                                        
  namespace: default                                                       
  selfLink: /api/v1/namespaces/default/services/hello-world                
spec:                                                                      
  ports:                                                                   
  - nodePort: 31595                                                        
    port: 80                                                               
    protocol: TCP                                                          
    targetPort: 80                                                         
  selector:                                                                
    run: hello-world                                                       
  sessionAffinity: None                                                    
  type: ExternalName
  externalName: minikube.local.com                                                           
status:                                                                    
  loadBalancer: {}                                                        

这是我的 ingress.yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: minikube-local-ingress
spec:
  rules:
  - host: minikube.local.com
    http:
      paths:
      - path: /
        backend:
          serviceName: hello-world
          servicePort: 80

所以,如果我进入 hello-world pod 并且从 /bin/bash 将 运行 curl minikube.local.comnslookup minikube.local.com.

那么我如何确保 pods 可以解析服务的 DNS 名称? 我知道我可以在部署定义中指定 hostAlias,但是是否有一种自动方式允许更新 kubernetes 的 DNS?

那么,您想在 Minikube 上公开您的应用程序吗?我刚刚尝试使用默认的 ClusterIP 服务类型(本质上,删除你拥有的 ExternalName 东西)并且使用 this YAML file 我可以在 https://192.168.99.100 上看到你的服务入口控制器存活时间:

服务现在看起来像这样:

apiVersion: v1
kind: Service
metadata:
  labels:
    run: hello-world
  name: hello-world
spec:
  ports:
  - port: 80
    targetPort: 80
  selector:
    run: hello-world

入口是:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: minikube-local-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host:
    http:
      paths:
      - path: /
        backend:
          serviceName: hello-world
          servicePort: 80

注意:在集群内,您的服务现在可以通过 hello-world.default(这是集群内 Kubernetes 分配的 DNS 名称)使用,而从外部您需要映射,比如 hello-world.local到主机上 /etc/hosts 文件中的 192.168.99.100。

或者,如果您将 Ingress 资源更改为 - host: hello-world.local,那么您可以(从主机)使用此 FQDN 访问您的服务,如下所示:curl -H "Host: hello-world.local" 192.168.99.100.