minikube服务%servicename%–url什么都不返回

我试图揭露我的API,所以我可以发送请求。 但是,当我使用命令minikube service api --url我什么也没有得到。 我所有的豆荚都运行良好根据kubectl get pods所以我高兴这可能是卡住了。

 api-1007925651-0rt1n 1/1 Running 0 26m auth-1671920045-0f85w 1/1 Running 0 26m blankit-app 1/1 Running 5 5d logging-2525807854-2gfwz 1/1 Running 0 26m mongo-1361605738-0fdq4 1/1 Running 0 26m jwl:.build jakewlace$ kubectl get services NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE api 10.0.0.194 <none> 3001/TCP 23m auth 10.0.0.36 <none> 3100/TCP 23m kubernetes 10.0.0.1 <none> 443/TCP 5d logging 10.0.0.118 <none> 3200/TCP 23m mongo 10.0.0.132 <none> 27017/TCP 23m jwl:.build jakewlace$ jwl:.build jakewlace$ minikube service api --url jwl:.build jakewlace$ 

任何帮助将大规模赞赏,谢谢。

我意识到,这里的问题可能被认为是最小的,但是这是因为我不确定从我一直遵循的教程中可以显示的更多信息应该可以工作。 如果你需要更多的信息,请让我知道我会让你知道。

编辑:

API-service.yml

 apiVersion: v1 kind: Service metadata: creationTimestamp: null labels: io.kompose.service: api name: api spec: ports: - name: "3001" port: 3001 targetPort: 3001 selector: io.kompose.service: api status: loadBalancer: {} 

API-deployment.yml

 apiVersion: extensions/v1beta1 kind: Deployment metadata: creationTimestamp: null labels: io.kompose.service: api name: api spec: replicas: 1 strategy: {} template: metadata: creationTimestamp: null labels: io.kompose.service: api spec: containers: - image: blankit/web:0.0.1 name: api imagePullPolicy: IfNotPresent ports: - containerPort: 3001 resources: {} restartPolicy: Always status: {} 

你的configuration是好的,但只是缺less一件事。

在Kubernetes中有很多types的服务 ,但在这种情况下,您应该了解其中的两个:

ClusterIP服务:
在集群内部的IP上公开该服务。 select此值使服务只能从群集内访问。 这是默认的。

NodePort:
在静态端口(NodePort)上显示每个节点的IP上的服务。 将自动创buildNodeIP服务将路由到的一个ClusterIP服务。 您可以通过请求<NodeIP>:<NodePort> ,从集群外部联系NodePort服务。

注意:
如果您有一个多节点集群,并且已经公开了一个NodePort服务 ,则可以从同一端口上的任何其他节点进行访问,而不必将该Pod部署到同一个节点上。

所以,回到你的服务,你应该在你的规范中指定服务types:

 kind: Service apiVersion: v1 metadata: ... spec: type: NodePort selector: ... ports: - protocol: TCP port: 3001 

现在,如果你使用minikube service api --url ,它应该返回一个类似于http://<NodeIP>:<NodePort>的URL。

注意:默认的Kubernetesconfiguration会从30000-32767中select一个随机的端口。 但是如果需要的话,你可以覆盖它。


有用的参考:

  • Kubernetes /出版服务 – 服务types
  • Kubernetes /使用服务将前端连接到后端