大网数据广告活动
服务器运维问答

Exposing service in Kubernetes

· 52CE 我爱测

I'm new in Kubernetes and there are some doubts I have. I have setup a Kubernetes cluster that consists of one master/node and one node. I have deployed a very simple NodeJS-based app, using Deployment kind with 2 replicas. Then,…

问题原文

原帖链接 · Héctor · CC BY-SA 3.0

I'm new in Kubernetes and there are some doubts I have. I have setup a Kubernetes cluster that consists of one master/node and one node. I have deployed a very simple NodeJS-based app, using Deployment kind with 2 replicas. Then, I have exposed it as a service by kubectl expose deployment my-app --port=80.

Now, my services looks like:

root@sw-kubernetes01:~# kubectl get services
NAME             CLUSTER-IP        EXTERNAL-IP   PORT(S)   AGE
my-app           192.168.100.167   <none>        80/TCP    10m
kubernetes       192.168.100.1     <none>        443/TCP   1h

Is it supposed that I should access to my app navigating to http://192.168.100.167:? I'm getting a timeout error. Otherwise, how can I get the external IP to access to the service externally?

I know that if I declare the service as type: NodePort, I can access my app using nodes IP, doesn't exist a way to auto-balance the load between pods?

已采纳解答

原帖链接 · Naveen · CC BY-SA 3.0

If you are working on local cluster you could use the --type=NodePort

kubectl expose deployment my-app --port=80 --type=NodePort

and then grep for the port

kubectl get svc my-service -o yaml | grep nodePort

and you could browse that using the cluster ip and the port which is output from the previous grep result.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。