This guide explains how to access a running KUDO Cassandra instance from your application deployed within the same Kubernetes cluster.
- KUDO Cassandra instance running
- KUDO CLI installed
The examples below assume that the instance and namespace names are stored in the following shell variables. With this assumptions met, you should be able to copy-paste the commands easily.
instance_name=cassandra
namespace_name=default
kubectl get instance $instance_name -n $namespace_name
Example output:
NAME AGE
cassandra 16h
You will run simple cqlsh
command within an ephemeral pod on the Kubernetes
cluster to show how to connect to Cassandra.
In order to run cqlsh
you need a container image which has it. For simplicity,
you can use the same image which is used by the cassandra nodes. Run the
following command to retrieve its full name:
cassandra_image=$(kubectl get pod -n ${namespace_name} ${instance_name}-node-0 --template '{{ (index .spec.containers 0).image }}{{"\n"}}')
echo ${cassandra_image}
Example output:
mesosphere/cassandra:3.11.6-1.0.0
This command illustrates what DNS name to use to connect to Cassandra:
kubectl run --wait cassandra-access-demo --image=${cassandra_image} --restart=Never -- \
cqlsh --execute "describe cluster" ${instance_name}-svc.${namespace_name}.svc.cluster.local
Expected output:
pod/cassandra-access-demo created
Once the pod completes (which should take no more than a few seconds), you can see its output using a command such as the following:
kubectl logs cassandra-access-demo
Example output:
Warning: Cannot create directory at `/home/cassandra/.cassandra`. Command history will not be saved.
Cluster: cassandra1
Partitioner: Murmur3Partitioner
kubectl delete pod cassandra-access-demo
Expected output:
pod "cassandra-access-demo" deleted
The operator supports creation of a service that opens up ports to access Cassandra from outside the cluster. To enable this, you have to set the following variables:
kubectl kudo update $instance_name -n $namespace_name -p EXTERNAL_NATIVE_TRANSPORT=true
This will create a service with a LoadBalancer port that forwards to the Cassandra nodes. There are the following options:
- EXTERNAL_NATIVE_TRANSPORT="true" Enable access to the cluster from the outside
- EXTERNAL_RPC="true" Enable access to the legacy RPC port if it's enabled on the cluster (Requires that START_RPC is "true")
- EXTERNAL_NATIVE_TRANSPORT_PORT="9042" The external port that is forwarded to the native transport port on the nodes
- EXTERNAL_RPC_PORT="9160" The external port that is forwarded to the rpc port on the nodes
- EXTERNAL_SERVICE_ANNOTATIONS Annotations that are added to the external service. E.g., this can be used to configure ExternalDNS access
The EXTERNAL_SERVICE_ANNOTATIONS parameter can be used to set up ExternalDNS access when the external service is enabled. For example, one can set
EXTERNAL_SERVICE_ANNOTATIONS={"external-dns.alpha.kubernetes.io/hostname": "cassandra.example.org"}