[英]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.