我安装了 minikube 以在本地使用 kubernetes。我能够在本地创建 Pod 和服务。
但是,在其上运行的 pod(和容器)无法使用服务名称解析服务。
示例:我运行了 redis 服务,它充当 redis pod 的代理。kubectl get services
显示 taht redis 服务已创建。
但是,当我的 Web 应用程序尝试连接到 redis-service
时, 我得到连接超时,因为 Web 应用程序 (pod) 无法解析 redis-service
.
是否需要安装任何特殊的东西才能使服务解析在本地工作。
这是运行 kubectl get services
的输出
frontend 10.0.0.250 80/TCP 3h
kubernetes 10.0.0.1 <none> 443/TCP 3h
redis-service 10.0.0.156 <none> 6379/TCP 3h
rethinkdb-service 10.0.0.89 <none> 28015/TCP 3h
kubectl describe services --namespace=kube-system
Name: kube-dns
Namespace: kube-system
Labels: k8s-app=kube-dns,kubernetes.io/name=KubeDNS
Selector: <none>
Type: ClusterIP
IP: 10.0.0.10
Port: dns 53/UDP
Endpoints: 10.0.2.15:53
Port: dns-tcp 53/TCP
Endpoints: 10.0.2.15:53
Session Affinity: None
No events.
Name: kubernetes-dashboard
Namespace: kube-system
Labels: app=kubernetes-dashboard,kubernetes.io/cluster-service=true
Selector: app=kubernetes-dashboard
Type: NodePort
IP: 10.0.0.156
Port: <unset> 80/TCP
NodePort: <unset> 30000/TCP
Endpoints: 172.17.0.2:9090
Session Affinity: None
No events.
最佳答案
您需要将您的服务公开为 type: NodePort
在 minikube 中而不是 ClusterIP
然后您可以使用 minikube service <servicename>
访问它们
(或者您可以使用 kubectl get services
找出它们手动映射到的端口)
关于kubernetes - 服务解析在 minikube 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38296952/