要访问在Docker For Desktop中本地运行的Kubernetes服务? [英] Access a Kubernetes Service running locally in Docker For Desktop?
问题描述
我正在将Docker For Desktop与内置的Kubernetes集群一起使用。我安装了一个 Pod
通过HTTP提供资源,但是我不确定如何使用浏览器访问它。我有以下 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
对象上的code> 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:
- 还有另外一个<群集中已使用该端口的code>服务。删除其他
服务
,或将port
属性更改为无人认领的端口。 - 您的
Pod
尚未运行并准备就绪。检查kubectl获取吊舱
。
- There is another
Service
in your cluster that has claimed that port. Either delete the otherService
, or change theport
property to an unclaimed port. - Your
Pod
is not running and ready. Checkkubectl get pods
.
这篇关于要访问在Docker For Desktop中本地运行的Kubernetes服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!