如何从Localhost(例如Cassandra)上直接访问Localhost Kubernetes上的状态POD端口 - 需要什么路由?

发布于 2025-02-11 18:22:26 字数 955 浏览 1 评论 0原文

我想在Localhost上使用Kubernetes构建一些测试环境(可以是Docker桌面。Minikube,...)。我想将我的客户连接到Local -Host K8S集群中的Cassandra的3个实例。 cassandra是示例,它在etcd,redis,...或任何statefulset中可能相同。

  1. 我在Localhost Kubernetes上的同一端口上创建了statefulset
  2. 我创建服务以暴露每个吊舱。

我应该在用使用三个不同的名称Cassandra-0Cassandra-1Cassandra-2和同一端口的情况下进行操作。这是驱动程序所要求的 - 我无法转发单个端口,因为驾驶员需要在同一端口上运行所有实例。

因此,应该是Cassandra-0:9042Cassandra-1:9042Cassandra-0:9042

为了显示这一点,我创建了一些图形来以图形方式进行解释。

我想通过使用 ...-我不知道在K8S中使用什么 - 也许是服务。

I want to build some testing environment with use Kubernetes on localhost (can be Docker Desktop. minikube, ...). I want to connect my client to 3 instances of Cassandra inside localhost K8s cluster. Cassandra is example it can be same in etcd, redis, ... or any StatefulSet.

  1. I created StatefulSet with 3 replicas on same ports on localhost Kubernetes.
  2. I create Services to expose each pod.

What I should do next to route traffic with use three different names cassandra-0, cassandra-1, cassandra-2 and same port. This is required by driver - I can not forward individual ports since driver require to run all instances on same port.

So it should be cassandra-0:9042, cassandra-1:9042, cassandra-0:9042.

To shows this I create some drawing to explain it graphically.
enter image description here

I want achieve red line connection with use something ... - I do not know what to use in K8s - maybe services.

enter image description here

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

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

发布评论

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

评论(1

我很OK 2025-02-18 18:22:26

我要说的是,您应该定义一个节点端口并将您的请求发送到Localhost:NodePort

  ports: 
   - protocol: TCP 
     port: 8081 
     targetPort: 8080 
     nodePort: 32000

只需更改您的端口,以便它们满足您的需求。

如果您已经创建了一个端口的服务,请获取所有终点,然后尝试将流量转向它们。

kubectl get endpoints -A

I would say you should define a node port and send your request to localhost:NodePort

  ports: 
   - protocol: TCP 
     port: 8081 
     targetPort: 8080 
     nodePort: 32000

Just change your ports so they fit your needs.

If you already created a service with ports exposed, get all endpoints and try turn traffic towards them.

kubectl get endpoints -A
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文