Dns POD不会通过入口解析服务的域名

Dns POD不会通过入口解析服务的域名,dns,kubernetes,minikube,Dns,Kubernetes,Minikube,我有一个问题,我在minikube集群中的pod无法通过域名看到服务 要运行minikube,我使用以下命令(在windows 10上运行): minikube启动——虚拟机驱动程序hyperv minikube插件启用kube dns minikube插件允许进入 这是我的部署。yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: run: hello-world name: hello-w

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

要运行minikube,我使用以下命令(在windows 10上运行):
minikube启动——虚拟机驱动程序hyperv
minikube插件启用kube dns
minikube插件允许进入

这是我的
部署。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
这是
服务。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: {}                                                        
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
这是我的
入口。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: {}                                                        
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.com
nslookup minikube.local.com

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

那么,你想在Minikube上公开你的应用程序?我刚刚使用默认的
ClusterIP
服务类型尝试了它(基本上,删除了您拥有的
ExternalName
内容),我可以在
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名称),从外部,您需要在主机上的
/etc/hosts
文件中将其映射为
hello world.local
到192.168.99.100


或者,如果您将
ingres
资源更改为
-host:hello world.local
,则您可以(从主机)使用此FQDN访问您的服务,如下所示:
curl-H“host:hello world.local”192.168.99.100
?我不知道我是否理解您为什么要同时使用服务类型
ExternalName
ingres
资源?@MichaelHausenblas,这只是我现在的一个设置,它不必是
ExternalName
。我想创建一个服务,我希望任何具有相同名称空间的pod都能够通过DNS解析它。我有一个helloworld部署。我有一个指向此部署的服务。我希望有一个
my app
部署,能够将
minikube.local.com
解析为
hello world
服务,而无需在
my app
的主机文件中添加此映射。@MichaelHausenblas是否有此帮助?:)明白了,谢谢,解决方案马上就要出来了……当然,我明白了。因此,如果我部署一个新的pod(称之为
pod2
),我如何告诉pod通过这个特定的IP或DNS名称导航?因此,如果
pod2
想要与
hello world
通话,它需要访问
http://192.168.99.100
而不是
hello world。默认值为服务的内部IP地址。请阅读我写的内容。集群内部您的服务可以通过FQDN
hello world.default
,也就是说,如果您
curl
从集群内的任何位置执行此操作,则可以使用此服务。我还将为外部添加一个替代DNS解决方案…