K8ssandra Forum

How To: External IP for Port 9042

First lets create a Load Balancer with the following yaml:

apiVersion: v1
kind: Service
  name: k8ssandra-lb-service
  namespace: default
  - protocol: TCP
    port: 9042
    cassandra.datastax.com/cluster: k8ssandra
    cassandra.datastax.com/datacenter: dc1
  type: LoadBalancer

Next lets apply this yaml to our k8ssandra cluster:

kubectl apply -f k8ssandra-lb.yaml
service/k8ssandra-lb-service created

Now we should see this service has been created with an external IP:

kubectl get services        
NAME                                   TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)                                                 AGE
cass-operator-metrics                  ClusterIP    <none>          8383/TCP,8686/TCP                                       82d
k8ssandra-dc1-all-pods-service         ClusterIP      None           <none>          9042/TCP,8080/TCP,9103/TCP                              82d
k8ssandra-dc1-service                  ClusterIP      None           <none>          9042/TCP,9142/TCP,8080/TCP,9103/TCP,9160/TCP            82d
k8ssandra-dc1-stargate-service         ClusterIP   <none>          8080/TCP,8081/TCP,8082/TCP,8084/TCP,8085/TCP,9042/TCP   82d
k8ssandra-grafana                      ClusterIP    <none>          80/TCP                                                  82d
k8ssandra-kube-prometheus-operator     ClusterIP   <none>          443/TCP                                                 82d
k8ssandra-kube-prometheus-prometheus   ClusterIP    <none>          9090/TCP                                                82d
k8ssandra-lb-service                   LoadBalancer    9042:31462/TCP                                          3m28s
k8ssandra-reaper-reaper-service        ClusterIP      <none>          8080/TCP                                                82d
k8ssandra-seed-service                 ClusterIP      None           <none>          <none>                                                  82d
kubernetes                             ClusterIP      <none>          443/TCP                                                 82d
memegen-v2-service                     LoadBalancer   80:32590/TCP                                            78d
prometheus-operated                    ClusterIP      None           <none>          9090/TCP                                                82d

To demonstrate connectivity, I exec into my cass pod as it has cqlsh installed:

kubectl exec -it k8ssandra-dc1-default-sts-0 /bin/bash                                        

From the pod I execute cqlsh with the external IP with k8ssandra-superuser and password:

cassandra@k8ssandra-dc1-default-sts-0:/$ cqlsh 9042 -u k8ssandra-superuser -p H2mXvi6ftH8ZbW9i5k34

And viola, I am now connected to cassandra port 9042 with external IP address:

Connected to k8ssandra at
[cqlsh 5.0.1 | Cassandra 4.0-beta4 | CQL spec 3.4.5 | Native protocol v4]
Use HELP for help.

Last but not least, i delete this so you dont try to connect :slight_smile: :

kubectl delete -f k8ssandra-lb.yaml
service "k8ssandra-lb-service" deleted

Nice one. Could you also showcase steps on how to retrieve the cqlsh username and passwords? TY!

Sure I will post a new one right now. HOW TO: Access Cassandra & Create Cassandra Users

1 Like

ah, ok. I didn’t state it clearly earlier. I was going to see if you could refer to this documentation, K8ssandra security | K8ssandra, Apache Cassandra on Kubernetes, but yeah good to have another how-to article. Thank you!