Skip to content

Latest commit

 

History

History
164 lines (97 loc) · 8.46 KB

README.md

File metadata and controls

164 lines (97 loc) · 8.46 KB

docker-operator

A Docker Container for deploying the MariaDB Operator to Digital Ocean K8s Service

Demo to deploy MariaDB Operator and PhotoPrism Application with Docker/Terraform

License GitHub stars GitHub forks

This project is designed to create a containerised Kubernetes infrastructure on DigitalOcean, and then deploy:

For this demonstration to work, you will require various third party accounts.


Terms of use

Nothing in this demonstration is designed to be used in production and this is not supplied, supported or endorsed by MariaDB.

Please note the free $200 credit is enough to run this demonstration, however, if you do not decommission your services, or you use more than the free credit you will be liable for the cost. Don't worry, Digital Ocean makes it easy to do with a cascade delete of related resources, and there is a terraform script for that purpose just in case.

Prerequisites

You!

You require a certain level of technical knowledge to complete this, as you are required to install some tools to your computer.

The demonstration is designed to run within a Docker Environment.

Third Party Accounts

You will require FREE accounts for:

Digital Ocean supports Single Sign On (SSO) using your GitHub account. SSO allows easy navigation between the services and allows you to link the accounts together.

It is important to create your Github account before creating the other accounts.


Getting Started

Hopefully you have already created the Third Party Accounts required. Before you begin, simply realize that you'll be building a local container to run terraform scripts, that in turn create the remote Kubernetes cluster on Digital Ocean.

(1) Create a local directory for development, and then fork this repo to it. https://github.com/mariadb-developers/docker-operator

Then fork the remaining repositories that support the main one.

(2) You may want to change a few settings in your your newly forked docker-operator repo, regarding how Terraform will create the target DO K8s cluster. You can find the reference values for region, droplet (virtual machine) and Kubernetes versions here on Digital Ocean's documentation.

The cluster.tf file is what controls the K8s deployment parameters, and is where you make edits.

  • RECOMMENDED: Change Region setting at Line 3.
  • RECOMMENDED: Check Digitial Ocean's K8s version slug at Line 6 for currency/accuracy, as DO changes it frequently.
  • OPTIONAL: K8s node pool size / resource allocation at line 11.

Note that DO's node pool slugs documentation is in a different location.

(3) Login to DO, and Create your DO API token. For non-production purposes like this, using full permissions is recommeded, choose an expiration timeframe that suits you, then save it somewhere secure on your local machine. You'll use that in next step.

(4) copy .env.example to .env , and add your DO API key to the file and save it.

Copy the .env.example file and add your API KEY from Digital Ocean.

(5) With edits in your forked repo done, now you can build the dockerfile and run the created container. Run these commands while in the same directory as this readme.md file.

docker compose build --no-cache
docker compose up -d

(6) To make it easy, there is a make script to set up your kubernetes environment. Get the Container ID of your running container by using $ docker ps. Then connect to your Docker Container by running: $ docker exec -it containerID /bin/sh

Then you can run the make targets. The apply-demo will take a moment to complete, so be patient and watch the output until that operation completes and the K8s cluster is built.

make init-demo
make plan-demo
make apply-demo

(7) Once your Kubernetes Cluster is built you can run the following commands:

make initialise-helm
make prepare-operator

(8) You need to wait about 30 seconds for the operator to become available. Then you can run:

make install-operator

(9) After three minutes you can check the pods are available:

kubectl get pods

NAME                                                READY   STATUS    RESTARTS   AGE
mariadb-galera-0                                    2/2     Running   0          2m27s
mariadb-galera-1                                    2/2     Running   0          2m27s
mariadb-galera-2                                    2/2     Running   0          2m27s
mariadb-galera-maxscale-0                           1/1     Running   0          63s
mariadb-operator-cert-controller-5c8f679ff4-d7m5h   1/1     Running   0          4m31s
mariadb-operator-db9bb8b74-68xhq                    1/1     Running   0          4m31s
mariadb-operator-webhook-555dc947cd-nvvgj           1/1     Running   0          4m31s

Make sure all containers report READY status before proceeding to the next step.

(10) You should now have a fully running Kubernetes Cluster with a MariaDB database environment. To install the PhotoPrism application run:

make install-photo-pvc

(11) After a few minutes you can get the services information and connect:

kubectl get svc 

(12) Find the maxscale-gui IP and connect to it via the IP address:8989 --> mariadb-operator / MaxScale11!

You will also find the service IP address for the Application.

destroy

The destroy command will delete the infrastructure. This is important, if you have finished using it, to stop getting charged. But please note, some resources such as Load Balancers and Storage will remain. Clearly, do not run this until you have finished.

make destroy-demo

If you are running the destroy command, it will ask you to confirm by typing yes at the prompt. Alternatively, go to the Digital Ocean console and delete the K8s cluster from the web console, checking yes when prompted to cascade delete the associated resources.

Contributing to this project

To contribute to this repository, follow these steps:

  1. Fork this repository.
  2. Create a branch: git checkout -b <branch_name>.
  3. Make your changes and commit them: git commit -m '<commit_message>'
  4. Push to the original branch: git push origin my-helm-repo/<location>
  5. Create the pull request.

Alternatively see the GitHub documentation on creating a pull request.

Contact

If you want to contact me you can reach me at [email protected].

License

This project uses the following license: MIT.

Disclaimer

Whilst, I might currently work for MariaDB, this work was originally created before my employment by MariaDB and any development to these scripts is done strictly in my own time. It is therefore not endorsed, supported by or recommend by MariaDB.