LoadBalancer 或 Nodeport 服务未从本地主机连接到 minikube 内的 pod

问题描述 投票:0回答:1

我正在尝试使用 LoadBalancer 作为 pod 的服务。 pod 内的容器(单容器 pod)正在侦听端口 8080 以通过 UDP 接收数据包。我已经手动检查了容器,它做的很好。但是,在创建 LoadBalancer 服务后,我无法将数据包从主机发送到位于 minikube 集群内的 pod。

这是我的 pod 和服务 yaml 文件。 我想将数据包发送到集群内的我的 pod。我创建了一项服务,您可以查看它。

服务确实监听但是我真的不明白我把它发送到externalIP:nodePort后数据包转发到哪里了

POD

apiVersion: v1
kind: Pod
metadata:
  name: tstream-deb
  labels:
    app: tstream-deb
spec:
  containers:
  - name: tstream-deb
    image: tstream-deb
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 8080
      protocol: UDP

服务

apiVersion: v1
kind: Service
metadata:
  name: tstream-deb
  labels:
    app: tstream-deb
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 30001
      protocol: UDP
  selector:
    name: tstream-deb
    app: tsream-deb
~

所以我的 pod 基本上监听数据包/消息并在 Golang 中做一些事情,我在本地以及在容器内测试它工作得很好。

如何从本地主机到 minikube 集群内部与我的 pod 进行交互。我也尝试过 minikube 隧道,但没有帮助。

docker kubernetes minikube kubernetes-nodeport
1个回答
0
投票

似乎问题在于使用

<externalIP>:<nodePort>
作为网络地址。

应该是

<externalIP>:<servicePort>(80)

<nodeIP>:<nodePort>(30001)

您还可以使用主机的端口转发来检查服务

kubectl port-forward svc/tstream-deb 3000:80

有了这个设置,使用

localhost:3000
作为网络地址

© www.soinside.com 2019 - 2024. All rights reserved.