A Kubernetes operator to manage RethinkDB clusters.
This Operator is built using the Operator SDK, which is part of the Operator Framework and manages one or more RethinkDB instances deployed on Kubernetes.
The first step is to deploy the RethinkDB Operator into the cluster where it
will watch for requests to create RethinkDBCluster resources, much like the native
Kubernetes Deployment Controller watches for Deployment resource requests.
The deploy directory contains the manifests needed to properly install the
Operator.
Create the service account for the operator.
kubectl create -f deploy/service_account.yamlNext, create the RBAC role and role-binding that grants the permissions necessary for the operator to function.
kubectl create -f deploy/role.yaml
kubectl create -f deploy/role_binding.yamlAdd the CRD to the cluster that defines the RethinkDB resource.
kubectl create -f deploy/crds/rethinkdb_v1alpha1_rethinkdbcluster_crd.yamlFinally, deploy the operator into the cluster.
$ kubectl create -f deploy/operator.yamlYou can watch the list of pods and wait until the Operator pod is in a Running state, it should not take long.
kubectl get pods -wl name=rethinkdb-operatorYou can have a look at the logs for troubleshooting if needed.
kubectl logs -l name=rethinkdb-operatorOnce the RethinkDB Operator is deployed, Have a look in the examples directory
for example manifests that create RethinkDB resources.
Once the Operator is deployed and running, we can create an example RethinkDB
cluster. The example directory contains several example manifests for creating
RethinkDB clusters using the Operator.
kubectl apply -f example/rethinkdb-minimal.yamlWatch the list of pods to see that each requested node starts successfully.
kubectl get pods -wl cluster=rethinkdb-minimal-exampleSimply delete the RethinkDB Custom Resource to remove the cluster.
kubectl delete -f example/rethinkdb-minimal.yamlThe RethinkDB Operator supports the use of Persistent Volumes for each node in the RethinkDB cluster. See rethinkdb-custom.yaml for the syntax to enable.
kubectl apply -f example/rethinkdb-custom.yamlWhen deleting a RethinkDB cluster that uses Persistent Volumes, remember to remove the left-over volumes when the cluster is no longer needed, as these will not be removed automatically.
kubectl delete rethinkdbcluster,pvc -l cluster=rethinkdb-custom-exampleYou can spin up a simple client Pod to test accessing the cluster. The following code will list the
names of each node in the cluster. See the full client in the examples directory.
r = require('rethinkdb');
fs = require('fs');
const SERVER_HOST = 'rethinkdb-minimal-example.default.svc.cluster.local';
const SERVER_PORT = 28015;
const SERVER_TIMEOUT = 10;
const SERVER_PASSWORD = fs.readFileSync('/etc/rethinkdb/credentials/admin-password', 'utf8');
r.connect({
host: SERVER_HOST,
port: SERVER_PORT,
timeout: SERVER_TIMEOUT,
password: SERVER_PASSWORD,
ssl: {
'ca': fs.readFileSync('/etc/rethinkdb/tls/ca.crt', 'utf8'),
'cert': fs.readFileSync('/etc/rethinkdb/tls/client.crt', 'utf8'),
'key': fs.readFileSync('/etc/rethinkdb/tls/client.key', 'utf8')
}
}, function (err, conn) {
if (err) throw err;
r.db('rethinkdb').table('server_status').pluck('name').run(conn, function (err, res) {
if (err) throw err;
res.toArray(function (err, results) {
if (err) throw err;
console.log(results);
process.exit();
});
});
});Local development is usually done with minikube or minishift.
When using minikube for local development and testing, it may be necessary to increase the resources for the minikube VM.
minikube start --cpus 2 --memory 8192 --disk-size 40gClone the repository to a location on your workstation, generally this should be in someplace like $GOPATH/src/github.com/ORG/REPO.
Navigate to the location where the repository has been cloned and install the dependencies.
cd YOUR_REPO_PATH
dep ensure && dep statusOnce the dependencies are present, ensure the service account, role, role binding and CRD are added to your local cluster.
kubectl create -f deploy/service_account.yaml
kubectl create -f deploy/role.yaml
kubectl create -f deploy/role_binding.yaml
kubectl create -f deploy/crds/rethinkdb_v1alpha1_rethinkdbcluster_crd.yamlOnce the CRD is present, we can start the operator locally and begin development.
operator-sdk up local --namespace defaultYou can now create a RethinkDB resource to test your changes.
kubectl create -f example/rethinkdb-minimal.yamlKeep in mind that when you make changes to the code, you must restart the operator. Use Ctrl+c to kill the process and restart.
See the Changelog for the detail on what changed with each release.
RethinkDB Operator is released under the Apache 2.0 license. See the LICENSE file for details.