Using Couchbase Clients

The Kubernetes networking model poses some challenges when interacting with a Couchbase cluster. This document outlines some of the ways that Couchbase clients can connect with the cluster.

From a Pod in the Same Kubernetes Cluster

The recommended network model also happens to be the simplest: Run the client from a pod in the same Kubernetes cluster.

When a new Couchbase cluster is created, the operator also creates a headless service which creates A records for each Couchbase node, and an SRV record for the cluster as a whole.

To create a connection to the cluster from within the overlay (as a pod in the same Kubernetes cluster) you should use the SRV record to perform service discovery:

from couchbase.cluster import Cluster

c = Cluster('couchbase://{}-srv.default.svc.cluster.local'.format(cluster_name))

Where the domain is composed of my-cluster, which is the name of the CouchbaseCluster resource, the namespace and the domain of the cluster. Note that we use a separate service record to only advertise nodes with the data service enabled, this provides optimal bootstrapping of Couchbase clients.

Network Considerations

It may not be possible to connect clients to the cluster in all situations. Please refer to the main network document.