简体   繁体   中英

How can I access directly stateful pods ports on localhost Kubernetes from localhost (for example Cassandra) - what routing is need?

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. 在此处输入图像描述

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

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM