通过无头服务和端点从Kubernetes到开发机

发布于 2025-02-02 14:50:01 字数 1580 浏览 4 评论 0原文

我正在尝试使用无头服务 endpoint将群集中的流量转发到我的本地开发机器。我想在服务上的端口80上收听,并在端点上调用端口5002。我将其设置为这样:

无头服务(在端口80上以5002为5002的端口):

端点(指向我在端口5002上的开发计算机): ”端点Web“

我尝试curl http:// web:80从我的端口80上的任何pod中的80 。如果我curl http:// web:5002它成功通过并击中了我的开发机器。 targetPort是否应该向Web:80转到我的端口5002上的端点?

curl web:80

curl web:5002

一些附加信息:

  • 同一本地网络中
  • 我的群集和开发机在我使用的k3群集的
  • ,我只是想模仿kubernetes在这里做什么的桥梁,

这是明显的yaml:

apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: default
spec:
  clusterIP: None
  ports:
  - name: web
    port: 80
    targetPort: 5002
---
apiVersion: v1
kind: Endpoints
metadata:
  name: web
  namespace: default
subsets:
  - addresses:
      - ip: $HOST_IP
    ports:
      - name: web
        port: 5002
        protocol: TCP

I'm trying to use a headless service with an endpoint to forward traffic from within my cluster to my local development machine. I want to listen on port 80 on the service and call port 5002 on the endpoint. I have it setup as so:

Headless Service (listening on port 80 with a targetPort of 5002):
kubectl describe service web

Endpoint (pointing to my development computer on port 5002):
kubectl describe endpoints web

When I try to curl http://web:80 from any pod in my cluster on port 80 it times out. If I curl http://web:5002 it successfully goes through and hits my development machine. Shouldn't the targetPort make the request to web:80 go to my endpoint on port 5002?

curl web:80
curl web

curl web:5002
curl web:5002

Some additional info:

  • My cluster and dev machine are in the same local network
  • I'm using K3S on the cluster
  • I'm just trying to emulate what Bridge For Kubernetes does

Here is the manifest yaml:

apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: default
spec:
  clusterIP: None
  ports:
  - name: web
    port: 80
    targetPort: 5002
---
apiVersion: v1
kind: Endpoints
metadata:
  name: web
  namespace: default
subsets:
  - addresses:
      - ip: $HOST_IP
    ports:
      - name: web
        port: 5002
        protocol: TCP

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2025-02-09 14:50:01

我设法通过删除clusterip:无来使其工作。我的清单现在看起来像这样:

apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  type: ClusterIP
  ports:
  - name: web
    port: 80
    targetPort: 5002
---
apiVersion: v1
kind: Endpoints
metadata:
  name: web
subsets:
  - addresses:
      - ip: $HOST_IP
    ports:
      - name: web
        port: 5002

I managed to get it to work by removing the clusterIP: None. My manifest now looks like this:

apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  type: ClusterIP
  ports:
  - name: web
    port: 80
    targetPort: 5002
---
apiVersion: v1
kind: Endpoints
metadata:
  name: web
subsets:
  - addresses:
      - ip: $HOST_IP
    ports:
      - name: web
        port: 5002
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文