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

Viewed 65

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

1 Answers

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
Related