kubernetes - 服务解析在 minikube 中不起作用

标签 kubernetes

我安装了 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/

相关文章:

docker - 我们可以在 K8S 的 POD 中执行容器吗?

kubernetes - Kubelet在启动时失败:无法从输出中检测时钟速度: “”

kubernetes - K8s : why is there no easy way to get notifications if a pod becomes unhealthy and is restarted?

python - 使用 python 读取 Prometheus 指标

mongodb - 如何在 Kubernetes 中使用持久卷部署 MongoDB?

kubernetes - 如何使用 OpenStack Cinder 在 Kubernetes 集群中创建存储类并动态提供持久卷

nginx - 升级Kubernetes NGINX以在外部指标中使用StackDriver新资源模型

wordpress - 如何将Docker WordPress文件从initContainer复制到Kubernetes中的emptyDir中?

kubernetes - 无法将 Amazon Web Services (AWS) EBS 卷装入 Kubernetes pod

reactjs - 部署在k8s上的react应用程序的问题