CYBERTEC Logo

Kubernetes: Running the CYBERTEC PostgreSQL operator

11.2023 / Category: / Tags:

Kubernetes is a powerful and popular container orchestration platform that offers numerous benefits for organisations and developers. Many companies out there these days rely on Kubernetes (or some flavour of it including Rancher, OpenShift, etc.) to automate their environments.

PostgreSQL is perfectly suitable to run on Kubernetes. The way to handle a large relational database on a container orchestration platform is to use a thing called an “operator”. It takes care of all important features such as:

  • Running PostgreSQL
  • Backups and recovery
  • Upgrades and updates
  • … a lot more …

A Kubernetes operator is basically supported to be a replacement for a human “operator” handling all things “PostgreSQL” inside a Kubernetes deployment.

There are various operators for PostgreSQL out there. However, today we want to focus on the CYBERTEC PG operator which is available as Open Source inside our Github. repository. Feel free to check it out and run it in your environment without restrictions.

What is important to mention here: We are running using the CYBERTEC PG operator to manage thousands of instances around the world already. In other words: This code is reliable and just works. And if you find an area of improvement, we are open to pull requests.

In this blog you will learn how to use Minikube to run your first PostgreSQL cluster in your own local Kubernetes deployment.

Installing Minikube

Minikube is the easiest way to test Kubernetes locally on your machine. However, the procedure is the same in “real Kubernetes”. To make life easy for you we have included the deployment procedure of Minikube:

Now that we have installed Minikube, we can start it. In this case I have used Docker for virtualization. However, things such as VirtualBox are fine as well. Before running the following command make sure Docker is up and running:

Voila, Minikube is up and running. We can now work on PostgreSQL and test our shiny CYBERTEC PG operator. Deploying PostgreSQL is easiest when using a Helm chart. If you happen to be on Mac OS X it is therefore necessary to ensure that Helm is readily available:

Using

makes this really easy.
Now we have all we need: Kubernetes, Helm, etc. We can now follow up with:

  • Deploying the CYBERTEC PG Operator
  • Deploying our first cluster
  • Connecting to the cluster.

The entire process is really quick and should not take more than a couple of minutes. Of course this is true for Minikube. Deploying a full Enterprise grade Kubernetes / OpenShift infrastructure requires some more knowledge than just a sample cluster. However, I think this is a good way to get started.

Running your first PostgreSQL cluster on Kubernetes

After deploying a simple Minikube installation we can take a look at the next steps. One good way to start is to take a look at our Github page which has a lot more information.
You will find a lot more information there.

The first thing is to clone the desired Github repo:

Once we have cloned the repository and enter it we can create a Kubernetes namespace. For those of you who happen to use OpenShift we have also included the OpenShift equivalent:

Then we can deploy all those Helm charts. This is super easy as everything is fully automated inside those charts. The operators and all those additional components will be deployed seamlessly.

Wow, that was it. That is all it takes. The following command (for OpenShift) checks if the operators is indeed around:

Finally we can already deploy our first cluster. We can apply the desired YAML file containing our requirements. Here is what the YAML file might contain:

What we see here is the amount of CPU power we want to be assigned to, which type of storage we want and a lot more. In short: The YAML file describes what kind of PostgreSQL instance we are looking for.

In the next step we can use this file which is also part of our Github repo to make life easy for you and send it to the Kubernetes cluster:

If you want to do the same thing on OpenShift and not on Kubernetes use instead:

Once the new PostgreSQL instance has been deployed we can check what is going on inside Kubernetes to validate that all is working:

Note that this is optional - it is only needed for demonstration purposes to show that everything is indeed working.

Allowing traffic to your PostgreSQL server

Your first PostgreSQL database is now working inside Kubernetes. The next goal is to be able to connect to this server. To do that we first have to allow traffic to the instance and then figure out which passwords and so on we can use to actually connect and establish a database connection.

The first step is to sort out networking:

Voila, we now got a cluster IP. The service is accessible:

Mind the last line in the listing - it reveals that the IP in fact exists and is operational.

Obtaining connection information for PostgreSQL

The next piece of information we need is the password to create a database connection:

But there is more. We can determine the nodes in operation:

Connecting to PostgreSQL in Kubernetes

Voila, our first cluster is now operational. We can already run psql to connect to our shiny new database instance:

As you can see there are even two methods. We can create a normal database connection using psql and use the same information in our applications. Alternatively we can make use of the Pod-Shell to talk to PostgreSQL via Kubernetes.

Removing PostgreSQL instances from Kubernetes

Deploying new PostgreSQL instances in Kubernetes is easy and the same is true if we want to get rid of those database instances again.

Finally here is proof that the operation was indeed successful:

Conclusion

Running PostgreSQL is easy and offers a great deal of automation. Our operator is Open Source under an MIT license and can therefore be used free of charge (we of course provide full support). It has proven to work on thousands of systems worldwide - in short: We are talking about reliable, easy to use software. Please make sure that you checkout our blog on a regular basis - we will publish PostgreSQL and Kubernetes related content on a regular basis. So make sure that you don’t miss out.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
CYBERTEC Logo white
CYBERTEC PostgreSQL International GmbH
Römerstraße 19
2752 Wöllersdorf
Austria

+43 (0) 2622 93022-0
office@cybertec.at

Get the newest PostgreSQL Info & Tools


    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    ©
    2024
    CYBERTEC PostgreSQL International GmbH
    phone-handsetmagnifiercrosscross-circle
    0
    Would love your thoughts, please comment.x
    ()
    x
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram