Unless you are using Amazon Aurora or RDS, setting up clustering software still can be complicated and that’s why we want to offer options to simplify database cluster management in Amazon AWS. This time I will be looking at Percona Kubernetes Operators, for both Percona XtraDB Cluster and Percona Server for MongoDB.
Some time ago I showed some examples in Google Cloud in my post Percona DBaaS CLI to Simplify Deployment in Kubernetes, and now it’s time to take a look at AWS. The assumption is that you have Amazon Elastic Kubernetes Service running already; if not, there should be plenty of resources to look at and this is out of our scope.
To manage Kubernetes resources and Percona Kubernetes Operators we need access to a kubeconfig. Although it is possible to create kubeconfig manually, the easiest way to get it is to use the aws command line utility:
1 | aws eks --region us-east-2 update-kubeconfig --name my-cluster2 |
Now I also assume you have a node pool running, which will be used to run our database instances on.
The easiest way to create Percona XtraDB Cluster is:
1 | percona-dbaas mysql create-db cluster1 |
You will see confirmation of the successful operation:
1 2 3 4 5 6 7 8 9 10 | Starting.......................................[done] Database started successfully, connection details are below: Provider: k8s Engine: pxc Resource Name: cluster1 Resource Endpoint: cluster1-proxysql.default.pxc.svc.local Port: 3306 User: root Pass: 28DQwnhtbDveIIvn Status: ready |
And for Percona Server for MongoDB, the command is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | percona-dbaas mongodb create-db cluster1 Starting........................[done] Database started successfully, connection details are below: Provider: k8s Engine: psmdb Resource Name: cluster1 Resource Endpoint: cluster1-rs0.default.psmdb.svc.local Port: 27017 User: clusterAdmin Pass: LkXSJHhgZMg2UiYlgC Status: ready To access database please run the following commands: kubectl port-forward svc/cluster1-rs0 27017:27017 & mongo mongodb://clusterAdmin:LkXSJHhgZMg2UiYlgC@localhost:27017/admin?ssl=false |
And just in a single command, we have 3 nodes of MongoDB replica-sets running, which we can check with:
1 2 3 4 5 | kubectl get pods NAME READY STATUS RESTARTS AGE cluster1-rs0-0 1/1 Running 0 3m15s cluster1-rs0-1 1/1 Running 0 2m38s cluster1-rs0-2 1/1 Running 0 2m14s |
There are a few points to review.
External Connection
As you can see, the command mongo mongodb://clusterAdmin:LkXSJHhgZMg2UiYlgC@localhost:27017/admin?ssl=false offers to connect from the localhost. How do we connect to the replica set from the outside network?
This can be done by creating LoadBalancer service in EKS, and AWS will automatically assign the public IP address:
1 2 3 4 5 | kubectl expose service cluster1-rs0 --type=LoadBalancer --name=cluster1-rs0-service kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE cluster1-rs0-service LoadBalancer 10.100.226.122 a636d79b2646b4b12b10e3a1637f8f28-1009994397.us-east-2.elb.amazonaws.com 27017:31807/TCP 26s |
And we can connect to our Percona Server for MongoDB instances as:
1 | mongo mongodb://clusterAdmin:LkXSJHhgZMg2UiYlgC@a636d79b2646b4b12b10e3a1637f8f28-1009994397.us-east-2.elb.amazonaws.com:27017/admin?ssl=false |
Or you can create external access from the percona-dbaas with:
1 | percona-dbaas mysql create-db db-cluster1 --options="proxysql.serviceType=LoadBalancer" |
Storage Type
Another thing you may want to customize is the storage type.
By default, you will see:
1 2 3 4 5 | kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE mongod-data-cluster1-rs0-0 Bound pvc-ab619e95-9784-4e3f-9b98-0122cff8a564 6Gi RWO gp2 11m mongod-data-cluster1-rs0-1 Bound pvc-220a447e-3891-425b-86dd-9839878dd13c 6Gi RWO gp2 10m mongod-data-cluster1-rs0-2 Bound pvc-f2280389-4642-4592-bc99-2afe2c54fcc3 6Gi RWO gp2 10m |
The default-created storage class is “gp2”, which you can confirm from Amazon EC2 console:
(volumes were created and assigned automatically)
Volume Size
The default volume size is 6Gi, and it is also customizable:
1 | percona-dbaas mongodb create-db --options "replsets.volumeSpec.persistentVolumeClaim.resources.requests=storage:250Gi” cluster4 |
The command will create volumes 250Gi in size.
Takeaways
The points I wanted to show with this post are:
- Creating database clusters in AWS should not be complicated, even beside Aurora and RDS.
- At Percona we offer solutions you can use to create Percona XtraDB Cluster and Percona Server for MongoDB replicasets in minutes.
- Kubernetes by itself may sound complicated, but it really allows us to simplify a lot of operations.
Learn more about the history of Oracle, the growth of MongoDB, and what really qualifies software as open source. If you are a DBA, or an executive looking to adopt or renew with MongoDB, this is a must-read!