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<br> |
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 |
Starting.......................................[done]<br>Database started successfully, connection details are below:<br>Provider: k8s<br>Engine: pxc<br>Resource Name: cluster1<br>Resource Endpoint: cluster1-proxysql.default.pxc.svc.local<br>Port: 3306<br>User: root<br>Pass: 28DQwnhtbDveIIvn<br>Status: ready<br> |
And for Percona Server for MongoDB, the command is:
|
1 |
percona-dbaas mongodb create-db cluster1<br><br>Starting........................[done]<br>Database started successfully, connection details are below:<br>Provider: k8s<br>Engine: psmdb<br>Resource Name: cluster1<br>Resource Endpoint: cluster1-rs0.default.psmdb.svc.local<br>Port: 27017<br>User: clusterAdmin<br>Pass: LkXSJHhgZMg2UiYlgC<br>Status: ready<br><br>To access database please run the following commands:<br>kubectl port-forward svc/cluster1-rs0 27017:27017 &<br>mongo mongodb://clusterAdmin:LkXSJHhgZMg2UiYlgC@localhost:27017/admin?ssl=false<br> |
And just in a single command, we have 3 nodes of MongoDB replica-sets running, which we can check with:
|
1 |
kubectl get pods<br>NAME READY STATUS RESTARTS AGE<br>cluster1-rs0-0 1/1 Running 0 3m15s<br>cluster1-rs0-1 1/1 Running 0 2m38s<br>cluster1-rs0-2 1/1 Running 0 2m14s<br> |
There are a few points to review.
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 |
kubectl expose service cluster1-rs0 --type=LoadBalancer --name=cluster1-rs0-service<br><br>kubectl get service<br>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE<br>cluster1-rs0-service LoadBalancer 10.100.226.122 a636d79b2646b4b12b10e3a1637f8f28-1009994397.us-east-2.elb.amazonaws.com 27017:31807/TCP 26s<br> |
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"<br> |
Another thing you may want to customize is the storage type.
By default, you will see:
|
1 |
kubectl get pvc<br>NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE<br>mongod-data-cluster1-rs0-0 Bound pvc-ab619e95-9784-4e3f-9b98-0122cff8a564 6Gi RWO gp2 11m<br>mongod-data-cluster1-rs0-1 Bound pvc-220a447e-3891-425b-86dd-9839878dd13c 6Gi RWO gp2 10m<br>mongod-data-cluster1-rs0-2 Bound pvc-f2280389-4642-4592-bc99-2afe2c54fcc3 6Gi RWO gp2 10m<br> |
The default-created storage class is “gp2”, which you can confirm from Amazon EC2 console:

(volumes were created and assigned automatically)
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<br> |
The command will create volumes 250Gi in size.
The points I wanted to show with this post are:
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!