简体   繁体   English

如何使用 nodeport Kubernetes 连接到主节点

[英]How to connect to the master node using nodeport Kubernetes

I have two pods running on two different VM in the cluster one on the master node and other on the worker node.我有两个 Pod 在集群中的两个不同 VM 上运行,一个在主节点上,另一个在工作节点上。 I have the following docker file exposed port 31700 on the server-side and IP address of server VM node is 192.168.56.105 and for client-side VM IP address is 192.168.56.106.我在服务器端有以下 docker 文件公开端口 31700,服务器 VM 节点的 IP 地址为 192.168.56.105,客户端 VM 的 IP 地址为 192.168.56.106。

Dockerfile文件

EXPOSE 31700

Server file服务器文件

 sock = socket()
 sock.bind(('0.0.0.0',31700))

Client file客户档案

 sock.connect(('192.168.56.105',31700))

Pod : kubectl get pods Pod: kubectl get pods

 NAME      STATUS   ROLES    AGE   VERSION
 kmaster   Ready    master   25h   v1.19.3
 knode     Ready    worker   25h   v1.19.3

Service : kubectl get services服务: kubectl get services

 NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
 kubernetes      ClusterIP   10.96.0.1        <none>        443/TCP        25h
 myapp-service   NodePort    10.108.144.147   <none>        80:31700/TCP   49m

Detail of the service is described below:服务详情如下:

kubectl describe services myapp-service

Name:                     myapp-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=edge-server
Type:                     NodePort
IP:                       10.108.144.147
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  31700/TCP
Endpoints:                192.168.189.5:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

When I try to ping through the below command I retrieve Connection refused on both the VMs当我尝试通过以下命令 ping 时,我在两个 VM 上都检索到连接被拒绝

 curl -v https://192.168.56.105:31700    

I am able to ping the two pods.我能够 ping 两个豆荚。 Please help me in this on connecting the server and client.请帮助我连接服务器和客户端。 Help is highly appreciated.非常感谢帮助。 Thank you for your wonderful support.感谢您的大力支持。

You need to use port-forwarding to access applications in your cluster您需要使用端口转发来访问集群中的应用程序
(see https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/ ). (参见https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/ )。

You can forward a local port to a port on the Pod with:您可以使用以下命令将本地端口转发到Pod 上的端口

kubectl port-forward service/kubernetes <local-port>:443

myapp-service is exposing (listening to) 31700, but you should use port 80. myapp-service正在公开(侦听)31700,但您应该使用端口 80。

在您的 Dockerfile 中,它应该是“EXPOSE 80”而不是“EXPOSE 31700”(假设您的容器侦听端口 80)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 NodePort 服务连接到 kubernetes 中的 redis pod - Not able to connect to redis pod in kubernetes using NodePort service 如何在 Kubernetes 集群中获取 NodePort 服务的 NodePort 的 tcpdump? - How can take tcpdump of a NodePort of a NodePort service in Kubernetes cluster? 如何在服务节点端口范围默认范围之外的NodePort上启动kubernetes服务? - How to start kubernetes service on NodePort outside service-node-port-range default range? Kubernetes - NodePort 服务只能在部署了 pod 的节点上访问 - Kubernetes - NodePort service can be accessed only on node where pod is deployed Kube.netes NodePort 自定义端口 - Kubernetes NodePort Custom Port Kubernetes NodePort 连接被拒绝 - Kubernetes NodePort connection refused 如果主节点在 kubernetes 中死亡会怎样? 如何解决问题? - What happens if master node dies in kubernetes? How to resolve the issue? Kubernetes NodePort 无法正常工作 - Kubernetes NodePort not working correctly Kubernetes 服务节点端口不工作 - Kubernetes Service Nodeport is not working Kubernetes 使用 Docker,我们是否需要在包括 Kubernetes 主节点在内的所有节点上使用 docker CRI? - Kubernetes using Docker, do we need docker CRI on all nodes including Kubernetes Master Node?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM