Overview
KubeDB is the Kubernetes Native Database Management Solution which simplifies and automates routine database tasks such as Provisioning, Monitoring, Upgrading, Patching, Scaling, Volume Expansion, Backup, Recovery, Failure detection, and Repair for various popular databases on private and public clouds. The databases supported by KubeDB include MongoDB, Elasticsearch, MySQL, MariaDB, Redis, PostgreSQL, FerretDB, Percona XtraDB, and Memcached. Additionally, KubeDB also supports ProxySQL, PgBouncer and the streaming platform Kafka. You can find the guides to all the supported databases in KubeDB . In this tutorial we will deploy FerretDB in Azure Kubernetes Service (AKS) Using KubeDB. We will cover the following steps:
- Install KubeDB
- Deploy FerretDB
- Connect with FerretDB
- Read/Write Sample Data
Get Cluster ID
We need the cluster ID to get the KubeDB License. To get cluster ID, we can run the following command:
$ kubectl get ns kube-system -o jsonpath='{.metadata.uid}'
8e336615-0dbb-4ae8-b72f-2e7ec34c399d
Get License
Go to Appscode License Server to get the license.txt file. For this tutorial we will use KubeDB.
Install KubeDB
We will use helm to install KubeDB. Please install helm here
if it is not already installed.
Now, let’s install KubeDB
.
$ helm search repo appscode/kubedb
NAME CHART VERSION APP VERSION DESCRIPTION
appscode/kubedb v2024.3.16 v2024.3.16 KubeDB by AppsCode - Production ready databases...
appscode/kubedb-autoscaler v0.29.0 v0.29.1 KubeDB Autoscaler by AppsCode - Autoscale KubeD...
appscode/kubedb-catalog v2024.3.16 v2024.3.16 KubeDB Catalog by AppsCode - Catalog for databa...
appscode/kubedb-community v0.24.2 v0.24.2 KubeDB Community by AppsCode - Community featur...
appscode/kubedb-crd-manager v0.0.8 v0.0.8 KubeDB CRD Manager by AppsCode
appscode/kubedb-crds v2024.3.16 v2024.3.16 KubeDB Custom Resource Definitions
appscode/kubedb-dashboard v0.20.0 v0.20.0 KubeDB Dashboard by AppsCode
appscode/kubedb-enterprise v0.11.2 v0.11.2 KubeDB Enterprise by AppsCode - Enterprise feat...
appscode/kubedb-grafana-dashboards v2024.3.16 v2024.3.16 A Helm chart for kubedb-grafana-dashboards by A...
appscode/kubedb-kubestash-catalog v2024.3.16 v2024.3.16 KubeStash Catalog by AppsCode - Catalog of Kube...
appscode/kubedb-metrics v2024.3.16 v2024.3.16 KubeDB State Metrics
appscode/kubedb-one v2023.12.28 v2023.12.28 KubeDB and Stash by AppsCode - Production ready...
appscode/kubedb-ops-manager v0.31.0 v0.31.0 KubeDB Ops Manager by AppsCode - Enterprise fea...
appscode/kubedb-opscenter v2024.3.16 v2024.3.16 KubeDB Opscenter by AppsCode
appscode/kubedb-provider-aws v2024.3.16 v0.6.0 A Helm chart for KubeDB AWS Provider for Crossp...
appscode/kubedb-provider-azure v2024.3.16 v0.6.0 A Helm chart for KubeDB Azure Provider for Cros...
appscode/kubedb-provider-gcp v2024.3.16 v0.6.0 A Helm chart for KubeDB GCP Provider for Crossp...
appscode/kubedb-provisioner v0.44.0 v0.44.1 KubeDB Provisioner by AppsCode - Community feat...
appscode/kubedb-schema-manager v0.20.0 v0.20.0 KubeDB Schema Manager by AppsCode
appscode/kubedb-ui v2024.4.2 0.6.5 A Helm chart for Kubernetes
appscode/kubedb-ui-server v2021.12.21 v2021.12.21 A Helm chart for kubedb-ui-server by AppsCode
appscode/kubedb-webhook-server v0.20.0 v0.20.0 KubeDB Webhook Server by AppsCode
$ helm install kubedb oci://ghcr.io/appscode-charts/kubedb \
--version v2024.3.16 \
--namespace kubedb --create-namespace \
--set-file global.license=/path/to/the/license.txt \
--set global.featureGates.FerretDB=true \
--wait --burst-limit=10000 --debug
Let’s verify the installation:
$ kubectl get pods --all-namespaces -l "app.kubernetes.io/instance=kubedb"
NAMESPACE NAME READY STATUS RESTARTS AGE
kubedb kubedb-kubedb-autoscaler-65ff88c5f8-2v9v7 1/1 Running 0 3m43s
kubedb kubedb-kubedb-ops-manager-5d96b67f54-6wwtz 1/1 Running 0 3m43s
kubedb kubedb-kubedb-provisioner-7bb7565788-mrxwr 1/1 Running 0 3m44s
kubedb kubedb-kubedb-webhook-server-7fbf9bdc4c-gxfkw 1/1 Running 0 3m44s
kubedb kubedb-petset-operator-5d94b4ddb8-rcksz 1/1 Running 0 3m44s
kubedb kubedb-petset-webhook-server-6bd8b5d897-sfnth 2/2 Running 0 3m44s
kubedb kubedb-sidekick-5dc87959b7-txv4j 1/1 Running 0 3m44s
We can list the CRD Groups that have been registered by the operator by running the following command:
$ kubectl get crd -l app.kubernetes.io/name=kubedb
NAME CREATED AT
connectclusters.kafka.kubedb.com 2024-04-26T07:50:55Z
connectors.kafka.kubedb.com 2024-04-26T07:50:55Z
druidversions.catalog.kubedb.com 2024-04-26T07:50:18Z
elasticsearchautoscalers.autoscaling.kubedb.com 2024-04-26T07:50:48Z
elasticsearchdashboards.elasticsearch.kubedb.com 2024-04-26T07:50:48Z
elasticsearches.kubedb.com 2024-04-26T07:50:48Z
elasticsearchopsrequests.ops.kubedb.com 2024-04-26T07:50:48Z
elasticsearchversions.catalog.kubedb.com 2024-04-26T07:50:18Z
etcdversions.catalog.kubedb.com 2024-04-26T07:50:18Z
ferretdbs.kubedb.com 2024-04-26T07:50:51Z
ferretdbversions.catalog.kubedb.com 2024-04-26T07:50:18Z
kafkaautoscalers.autoscaling.kubedb.com 2024-04-26T07:50:55Z
kafkaconnectorversions.catalog.kubedb.com 2024-04-26T07:50:18Z
kafkaopsrequests.ops.kubedb.com 2024-04-26T07:50:55Z
kafkas.kubedb.com 2024-04-26T07:50:55Z
kafkaversions.catalog.kubedb.com 2024-04-26T07:50:18Z
mariadbarchivers.archiver.kubedb.com 2024-04-26T07:50:58Z
mariadbautoscalers.autoscaling.kubedb.com 2024-04-26T07:50:58Z
mariadbdatabases.schema.kubedb.com 2024-04-26T07:50:58Z
mariadbopsrequests.ops.kubedb.com 2024-04-26T07:50:58Z
mariadbs.kubedb.com 2024-04-26T07:50:58Z
mariadbversions.catalog.kubedb.com 2024-04-26T07:50:18Z
memcachedversions.catalog.kubedb.com 2024-04-26T07:50:18Z
mongodbarchivers.archiver.kubedb.com 2024-04-26T07:51:02Z
mongodbautoscalers.autoscaling.kubedb.com 2024-04-26T07:51:01Z
mongodbdatabases.schema.kubedb.com 2024-04-26T07:51:02Z
mongodbopsrequests.ops.kubedb.com 2024-04-26T07:51:01Z
mongodbs.kubedb.com 2024-04-26T07:51:01Z
mongodbversions.catalog.kubedb.com 2024-04-26T07:50:18Z
mysqlarchivers.archiver.kubedb.com 2024-04-26T07:51:05Z
mysqlautoscalers.autoscaling.kubedb.com 2024-04-26T07:51:05Z
mysqldatabases.schema.kubedb.com 2024-04-26T07:51:05Z
mysqlopsrequests.ops.kubedb.com 2024-04-26T07:51:05Z
mysqls.kubedb.com 2024-04-26T07:51:05Z
mysqlversions.catalog.kubedb.com 2024-04-26T07:50:18Z
perconaxtradbversions.catalog.kubedb.com 2024-04-26T07:50:18Z
pgbouncerversions.catalog.kubedb.com 2024-04-26T07:50:18Z
pgpoolversions.catalog.kubedb.com 2024-04-26T07:50:18Z
postgresarchivers.archiver.kubedb.com 2024-04-26T07:51:09Z
postgresautoscalers.autoscaling.kubedb.com 2024-04-26T07:51:09Z
postgresdatabases.schema.kubedb.com 2024-04-26T07:51:09Z
postgreses.kubedb.com 2024-04-26T07:50:51Z
postgresopsrequests.ops.kubedb.com 2024-04-26T07:51:09Z
postgresversions.catalog.kubedb.com 2024-04-26T07:50:18Z
proxysqlversions.catalog.kubedb.com 2024-04-26T07:50:18Z
publishers.postgres.kubedb.com 2024-04-26T07:51:09Z
rabbitmqversions.catalog.kubedb.com 2024-04-26T07:50:18Z
redisautoscalers.autoscaling.kubedb.com 2024-04-26T07:51:12Z
redises.kubedb.com 2024-04-26T07:51:12Z
redisopsrequests.ops.kubedb.com 2024-04-26T07:51:12Z
redissentinelautoscalers.autoscaling.kubedb.com 2024-04-26T07:51:12Z
redissentinelopsrequests.ops.kubedb.com 2024-04-26T07:51:12Z
redissentinels.kubedb.com 2024-04-26T07:51:12Z
redisversions.catalog.kubedb.com 2024-04-26T07:50:18Z
singlestoreversions.catalog.kubedb.com 2024-04-26T07:50:19Z
solrversions.catalog.kubedb.com 2024-04-26T07:50:19Z
subscribers.postgres.kubedb.com 2024-04-26T07:51:09Z
zookeeperversions.catalog.kubedb.com 2024-04-26T07:50:19Z
Deploy FerretDB with KubeDB Managed PostgreSQL
We are going to deploy FerretDB using KubeDB. First, let’s create a namespace in which we will deploy FerretDB.
$ kubectl create namespace demo
namespace/demo created
Here is the yaml of the FerretDB CR we are going to use:
apiVersion: kubedb.com/v1alpha2
kind: FerretDB
metadata:
name: ferret
namespace: demo
spec:
version: "1.18.0"
storageType: Durable
storage:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
backend:
externallyManaged: false
terminationPolicy: WipeOut
Let’s save this yaml configuration into ferret.yaml
Then create the above FerretDB CR
$ kubectl apply -f ferret.yaml
ferretdb.kubedb.com/ferret created
In this yaml,
spec.version
field specifies the version of FerretDB. Here, we are using FerretDB1.18.0
. You can list the KubeDB supported versions of FerretDB by running$ kubectl get ferretdbversions
command.spec.storageType
specifies the type of storage that will be used for FerretDB. It can beDurable
orEphemeral
. Default value of this field isDurable
.spec.backend
denotes the backend database information for FerretDB instance.spec.terminationPolicy
field is Wipeout means it will be deleted without restrictions.
Once these are handled correctly and the FerretDB object is deployed, you will see that the following objects are created:
$ kubectl get all -n demo
NAME READY STATUS RESTARTS AGE
pod/ferret-0 1/1 Running 0 3m44s
pod/ferret-pg-backend-0 2/2 Running 0 5m9s
pod/ferret-pg-backend-1 2/2 Running 0 4m11s
pod/ferret-pg-backend-arbiter-0 1/1 Running 0 4m1s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ferret ClusterIP 10.96.204.214 <none> 27017/TCP 5m13s
service/ferret-pg-backend ClusterIP 10.96.154.207 <none> 5432/TCP,2379/TCP 5m13s
service/ferret-pg-backend-pods ClusterIP None <none> 5432/TCP,2380/TCP,2379/TCP 5m13s
service/ferret-pg-backend-standby ClusterIP 10.96.58.213 <none> 5432/TCP 5m13s
NAME READY AGE
statefulset.apps/ferret-pg-backend 2/2 5m9s
statefulset.apps/ferret-pg-backend-arbiter 1/1 4m1s
NAME TYPE VERSION AGE
appbinding.appcatalog.appscode.com/ferret kubedb.com/ferretdb 1.18.0 3m44s
appbinding.appcatalog.appscode.com/ferret-pg-backend kubedb.com/postgres 13.13 4m1s
NAME VERSION STATUS AGE
postgres.kubedb.com/ferret-pg-backend 13.13 Ready 5m13s
Let’s check if the ferret
is ready to use,
$ kubectl get ferretdb -n demo ferret
NAME NAMESPACE VERSION STATUS AGE
ferret demo 1.18.0 Ready 5m44s
We have successfully deployed FerretDB in AKS.
Connect with FerretDB
We will use port forwarding to connect with FerretDB.
Port-forward the Service
KubeDB will create few Services to connect with the database. Let’s check the Services by following command,
$ kubectl get service -n demo | grep ferret
ferret ClusterIP 10.96.204.214 <none> 27017/TCP 6m
ferret-pg-backend ClusterIP 10.96.154.207 <none> 5432/TCP,2379/TCP 6m
ferret-pg-backend-pods ClusterIP None <none> 5432/TCP,2380/TCP,2379/TCP 6m
ferret-pg-backend-standby ClusterIP 10.96.58.213 <none> 5432/TCP 6m
Here, we are going to use Service named ferret
. Now, let’s port-forward the ferret
Service to the local machine’s port 27017
.
$ kubectl port-forward -n demo svc/ferret 27017
Forwarding from 127.0.0.1:27017 -> 27017
Forwarding from [::1]:27017 -> 27017
Access the Credentials
KubeDB also create Secret for the ferret
instance. Let’s check by following command,
$ kubectl get secret -n demo | grep ferret
ferret-pg-backend-auth kubernetes.io/basic-auth 2 12m
Now, we are going to use ferret-pg-backend-auth
to get the credentials.
$ kubectl get secrets -n demo ferret-pg-backend-auth -o jsonpath='{.data.username}' | base64 -d
postgres
$ kubectl get secrets -n demo ferret-pg-backend-auth -o jsonpath='{.data.password}' | base64 -d
d2ChBg0xZ!5YuC)j
Insert Sample Data
In this section, we will to log in via MongoDB Shell and insert some sample data.
$ mongosh 'mongodb://postgres:d2ChBg0xZ!5YuC)j@localhost:27017/ferretdb?authMechanism=PLAIN'
Current Mongosh Log ID: 662a115ba0c9708bf62202d7
Connecting to: mongodb://<credentials>@localhost:27017/ferretdb?authMechanism=PLAIN&directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.5
Using MongoDB: 7.0.42
Using Mongosh: 2.2.5
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2024-04-26T08:16:27.851Z: Powered by FerretDB v1.18.0 and PostgreSQL 13.13 on x86_64-pc-linux-musl, compiled by gcc.
2024-04-26T08:16:27.851Z: Please star us on GitHub: https://github.com/FerretDB/FerretDB.
2024-04-26T08:16:27.851Z: The telemetry state is undecided.
2024-04-26T08:16:27.851Z: Read more about FerretDB telemetry and how to opt out at https://beacon.ferretdb.io.
------
ferretdb> show dbs
kubedb_system 80.00 KiB
ferretdb> use musicdb
switched to db musicdb
musicdb> db.music.insertOne({"Avicii": "The Nights"})
{
acknowledged: true,
insertedId: ObjectId('662a11d7a0c9708bf62202d8')
}
musicdb> db.music.insertOne({"John Denver": "Annie's Song"})
{
acknowledged: true,
insertedId: ObjectId('662a11e0a0c9708bf62202d9')
}
musicdb> db.music.find()
[
{ _id: ObjectId('662a11d7a0c9708bf62202d8'), Avicii: 'The Nights' },
{
_id: ObjectId('662a11e0a0c9708bf62202d9'),
'John Denver': "Annie's Song"
}
]
musicdb> show dbs
kubedb_system 80.00 KiB
musicdb 80.00 KiB
musicdb> exit
Here, we’ve stored some sample data in our
ferret-pg-backend
PostgreSQL usingmongosh
.
Verify Data in PostgreSQL Backend Engine
Now, We are going to exec into the PostgreSQL pod to verify if the data has been stored successfully.
$ kubectl exec -it -n demo ferret-pg-backend-0 -- bash
Defaulted container "postgres" out of: postgres, pg-coordinator, postgres-init-container (init)
ferret-pg-backend-0:/$ psql
psql (13.13)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------+----------+----------+------------+------------+-----------------------
ferretdb | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
kubedb_system | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
postgres=# \c ferretdb
You are now connected to database "ferretdb" as user "postgres".
ferretdb=# \dn
List of schemas
Name | Owner
---------------+----------
kubedb_system | postgres
musicdb | postgres
public | postgres
(3 rows)
ferretdb=# SET search_path TO musicdb;
SET
ferretdb=# \dt
List of relations
Schema | Name | Type | Owner
---------+-----------------------------+-------+----------
musicdb | _ferretdb_database_metadata | table | postgres
musicdb | music_9f9c4fd4 | table | postgres
(2 rows)
ferretdb=# SELECT * FROM music_9f9c4fd4;
_jsonb
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"$s": {"p": {"_id": {"t": "objectId"}, "Avicii": {"t": "string"}}, "$k": ["_id", "Avicii"]}, "_id": "662a11d7a0c9708bf62202d8", "Avicii": "The Nights"}
{"$s": {"p": {"_id": {"t": "objectId"}, "John Denver": {"t": "string"}}, "$k": ["_id", "John Denver"]}, "_id": "662a11e0a0c9708bf62202d9", "John Denver": "Annie's Song"}
(2 rows)
ferretdb=# exit
Deploy FerretDB with Externally Managed PostgreSQL
In this blog post, we demonstrated how to deploy FerretDB with KubeDB Managed PostgreSQL. However, if you prefer to use your own PostgreSQL as the backend engine, you have the flexibility to do so. Below, we provide the yaml configuration for integrating FerretDB with an externally managed PostgreSQL instance.
apiVersion: kubedb.com/v1alpha2
kind: FerretDB
metadata:
name: ferretdb-external
namespace: demo
spec:
version: "1.18.0"
authSecret:
externallyManaged: true
name: ha-postgres-auth
storageType: Durable
storage:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
backend:
externallyManaged: true
postgres:
service:
name: ha-postgres
namespace: demo
pgPort: 5432
terminationPolicy: WipeOut
Here,
spec.postgres.serivce
is service information of users external postgres exist in the cluster.spec.authSecret.name
is the name of the authentication secret of users external postgres database.
We have created a detailed webinar demonstrating Seamlessly Provision and Manage FerretDB in Kubernetes Using KubeDB. You can watch the video below:
Support
To speak with us, please leave a message on our website .
To receive product announcements, follow us on X .
To watch tutorials of various Production-Grade Kubernetes Tools Subscribe to our YouTube channel.
If you have found a bug with KubeDB or want to request for new features, please file an issue .