问题描述
我已经使用以下命令运行了Hello World应用程序.
I have run a Hello World application using the below command.
kubectl运行hello-world --replicas = 2 --labels ="run = load-balancer-example" --image = gcr.io/google-samples/node-hello:1.0 --port =8080
创建如下服务
kubectl公开部署hello-world --type = NodePort --name = example-service
吊舱正在运行
NAME READY STATUS RESTARTS AGE
hello-world-68ff65cf7-dn22t 1/1 Running 0 2m20s
hello-world-68ff65cf7-llvjt 1/1 Running 0 2m20s
服务:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
example-service NodePort 10.XX.XX.XX <none> 8080:32023/TCP 66s
在这里,我可以通过集群内部的卷曲对其进行测试.
Here, I am able to test it through curl inside the cluster.
curl http://10.XX.XX.XX:8080
Hello Kubernetes!
如何在群集之外访问此服务?(例如,通过笔记本电脑浏览器)
How can I access this service outside my cluster? (example, through laptop browser)
推荐答案
您应该尝试
IP_OF_KUBERNETES可以是您的主IP,也可以是您的工作IP当您在kubernetes中公开一个端口时,它将在集群中所有服务器中公开该端口.假设您有两个工作节点,分别为IP1和IP2并且一个Pod在IP1中运行,而在worker2中没有Pod,但是您可以通过以下方式访问您的Pod:
IP_OF_KUBERNETES can be your master IP your worker IPwhen you expose a port in kubernetes .It expose that port in all of your server in cluster.Imagine you have two worker node with IP1 and IP2and one pode is running in IP1 and in worker2 there is no pods but you can access your pod by
这篇关于如何在k8s集群外公开服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!