本文介绍了访问在 Docker For Desktop 中本地运行的 Kubernetes 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Docker For Desktop 与内置的 Kubernetes 集群一起使用.我已经安装了一个通过 HTTP 提供资源的 Pod,但我不确定如何使用我的浏览器访问它.我有以下 ServiceSpec 可以正确地将流量路由到 Pod:

I'm using Docker For Desktop with the built-in Kubernetes cluster. I have installed a Pod that serves resources over HTTP, but I'm not sure how to access it using my browser. I have the following ServiceSpec that correctly routes traffic to the Pod:

spec:
  clusterIP: 10.99.132.220
  externalTrafficPolicy: Cluster
  ports:
  - name: myport
    nodePort: 31534
    port: 8037
    protocol: TCP
    targetPort: 80
  type: LoadBalancer

当我使用 kubectl 查询它时,我可以看到它的设置:

And I can see it set up when I query it with kubectl:

$ kubectl get service
NAME           TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
myservice   LoadBalancer   10.99.132.220   localhost     8037:31534/TCP   1h

如何使用浏览器访问此服务?

How do I reach this service using my browser?

推荐答案

该服务将在您的浏览器中提供,地址为 http://localhost:8037

That service will be available in your browser at http://localhost:8037

请注意,端口 8037 对应于 ServiceSpec 对象上的 port 属性.

Note that the port 8037 corresponds to the port property on the ServiceSpec object.

如果您无法通过该 URL 访问服务,则可能是以下几种情况之一,包括但不限于:

If you are unable to reach the service at that URL, then it could be one of several things, including but not limited to:

  • 您的集群中有另一个 Service 已声明该端口.删除其他 Service,或将 port 属性更改为未声明的端口.
  • 您的 Pod 未运行且未就绪.检查 kubectl get pods.
  • There is another Service in your cluster that has claimed that port. Either delete the other Service, or change the port property to an unclaimed port.
  • Your Pod is not running and ready. Check kubectl get pods.

这篇关于访问在 Docker For Desktop 中本地运行的 Kubernetes 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:07