The NDB operator brings automated and simplified database administration, provisioning, and life-cycle management to Kubernetes.
- NDB installation.
- A Kubernetes cluster to run against, which should have network connectivity to the NDB installation. You can use KIND to get a local cluster for testing, or run against a remote cluster.
Note: The operator will automatically use the current context in your kubeconfig file (i.e. whatever cluster
kubectl cluster-info
shows). - The operator-sdk installed.
- A clone of the source code (this repository).
Deploy the controller on the cluster:
make deploy
- Create the secrets that are to be used by the custom resource:
apiVersion: v1
kind: Secret
metadata:
name: your-ndb-secret
type: Opaque
stringData:
username: username-for-ndb-server
password: password-for-ndb-server
ca_certificate: |
-----BEGIN CERTIFICATE-----
CA CERTIFICATE (ca_certificate is optional)
-----END CERTIFICATE-----
---
apiVersion: v1
kind: Secret
metadata:
name: your-db-secret
type: Opaque
stringData:
password: password-for-the-database-instance
ssh_public_key: SSH-PUBLIC-KEY
- To create instances of custom resources (provision databases), edit ndb_v1alpha1_database.yaml file with the NDB installation and database instance details and run:
kubectl apply -f config/samples/ndb_v1alpha1_database.yaml
- To delete instances of custom resources (deprovision databases) run:
kubectl delete -f config/samples/ndb_v1alpha1_database.yaml
The ndb_v1alpha1_database.yaml is described as follows:
apiVersion: ndb.nutanix.com/v1alpha1
kind: Database
metadata:
# This name that will be used within the kubernetes cluster
name: db
spec:
# NDB server specific details
ndb:
# Cluster id of the cluster where the Database has to be provisioned
# Can be fetched from the GET /clusters endpoint
clusterId: "Nutanix Cluster Id"
# Credentials secret name for NDB installation
# data: username, password,
# stringData: ca_certificate
credentialSecret: your-ndb-secret
# The NDB Server
server: https://[NDB IP]:8443/era/v0.9
# Set to true to skip SSL verification, default: false.
skipCertificateVerification: true
# Database instance specific details (that is to be provisioned)
databaseInstance:
# The database instance name on NDB
databaseInstanceName: "Database-Instance-Name"
# Names of the databases on that instance
databaseNames:
- database_one
- database_two
- database_three
# Credentials secret name for NDB installation
# data: password, ssh_public_key
credentialSecret: your-db-secret
size: 10
timezone: "UTC"
type: postgres
- Install the CRDs into the cluster:
make install
- Run your controller locally (this will run in the foreground, so switch to a new terminal if you want to leave it running):
make run
NOTE: You can also run this in one step by running: make install run
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
make generate manifests
NOTE: Run make --help
for more information on all potential make
targets
More information can be found via the Kubebuilder Documentation
Build and push your image to the location specified by IMG
:
make docker-build docker-push IMG=<some-registry>/ndb-operator:tag
Deploy the controller to the cluster with the image specified by IMG
:
make deploy IMG=<some-registry>/ndb-operator:tag
To delete the CRDs from the cluster:
make uninstall
To remove the controller from the cluster:
make undeploy
This project aims to follow the Kubernetes Operator pattern
It uses Controllers which provides a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.
A custom resource of the kind Database is created by the reconciler, followed by a Service and an Endpoint that maps to the IP address of the database instance provisioned. Application pods/deployments can use this service to interact with the databases provisioned on NDB through the native Kubernetes service.
Pods can specify an initContainer to wait for the service (and hence the database instance) to get created before they start up.
initContainers:
- name: init-db
image: busybox:1.28
command: ['sh', '-c', "until nslookup <<Database CR Name>>-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for database service; sleep 2; done"]
See the contributing docs.
This code is developed in the open with input from the community through issues and PRs. A Nutanix engineering team serves as the maintainer. Documentation is available in the project repository.
Issues and enhancement requests can be submitted in the Issues tab of this repository. Please search for and review the existing open issues before submitting a new issue.
Copyright 2021-2022 Nutanix, Inc.
The project is released under version 2.0 of the Apache license.