A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.cybertec-postgresql.com/en/setting-sail-installing-cloud-native-postgresql-cnpg/ below:

Setting Sail: Installing Cloud Native PostgreSQL (CNPG) | CYBERTEC PostgreSQL

Introduction

The cloud has become an undeniably crucial part of our lives. It's pretty much everywhere across the entire IT sector. And for those who haven't jumped on board yet, honestly, it's not a matter of if but when.The simple reality is, if you are not in the cloud or at least making plans to be, you are seriously risking falling behind in the fast-paced digital world.

Now, when we are talking about modern cloud infrastructure, especially for running dynamic, scalable applications, there is one thing we just cannot imagine it without: Kubernetes.

It is the orchestrator that brings real order and efficiency to the massive power of distributed cloud computing. Whether you are building a straightforward web service or a complex microservices setup, Kubernetes gives you the solid foundation for resilience, scalability, and easy management. It is not just another tool; it's the absolute backbone of the cloud-native future.

Kubernetes does not only power up web services, but also PostgreSQL. escpecially with the help of Cloud Native PostgreSQL (CNPG). It lets us declaratively manage our PostgreSQL clusters, handle backups, scaling, and a whole lot more, all through simple Kubernetes manifests.

I want to give you a quick guide on how to get the CNPG operator up and running on your Minikube environment. It’s pretty straightforward, so let's dive in!

Applying The CNPG Manifest


First things first, we need to apply the CNPG operator's core manifest. The following command sets up everything required for the operator to function:

kubectl apply -f https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-1.26/releases/cnpg-1.26.0.yaml

With this command, a lot happens under the hood. Specifically, this manifest will deploy:

Verifying the Operator Deployment

Once you have applied the manifest, it is always a good practice to check that the controller has successfully deployed and is running without issues. We can check its rollout status with this command:

kubectl rollout status deployment -n cnpg-system cnpg-controller-manager

If everything went smoothly, you should see an output similar to this:

deployment "cnpg-controller-manager" successfully rolled out

This confirms that the CNPG operator is ready to accept your PostgreSQL cluster definitions.

Setting Our Context (Optional but Recommended)

From this point onwards, we will primarily be interacting within the cnpg-system namespace, especially when defining or managing our PostgreSQL clusters via CNPG. To save ourselves some typing and always targeting the correct namespace, we can set our default Kubernetes context:

kubectl config set-context --current --namespace=cnpg-system

Now, all subsequent kubectl commands (unless you explicitly specify a different namespace with -n) will automatically operate within the cnpg-system namespace. This just makes life a little easier.

Our Minikube environment is now equipped with the powerful Cloud Native PostgreSQL operator. We are all set to start defining and managing your PostgreSQL clusters in a truly cloud-native way.

So let's create our very first PostgreSQL cluster on Minikube. I am going to keep it super simple and create a single-instance database cluster without getting into too many fancy options just yet.

Preparing Our Cluster Manifest

Let' s create a manifest file named single.yaml. Its content will be:

apiVersion: postgresql.cnpg.io/v1

kind: Cluster

metadata:

  name: cluster-example

spec:

  instances: 1

  storage:

    size: 1Gi

In this brief manifest:

Applying the Manifest to Our Cluster

With our single.yaml file ready, it's time to tell Kubernetes to create our PostgreSQL cluster.

kubectl apply -f single.yaml

If everything goes well, you should see an output confirming the creation:

cluster.postgresql.cnpg.io/cluster-example created

This means Kubernetes has accepted your request, and the CNPG operator is now getting to work creating your PostgreSQL instance.

Validating the Deployment

Now, let's confirm that our PostgreSQL pod is actually up and running. We can check the status of our pods with kubectl get pods:

The output should look something like this, showing your cluster-example-1 pod in a Running state:

NAME               READY  STATUS   RESTARTS  AGE

cluster-example-1  1/1    Running  0         2m

Accessing the PostgreSQL

Connecting to our brand-new PostgreSQL pod's container and get to the psql shell.

kubectl exec -it pod/cluster-example-1 -- /bin/bash

You will see some initial messages, and then you will be inside the container. From there, just type psql to enter the PostgreSQL client:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

Defaulted container "postgres" out of: postgres, bootstrap-controller (init)

psql

psql (17.5 (Debian 17.5-1.pgdg110+1))

Type "help" for help.

postgres=# \du

                                 List of roles

     Role name     |                         Attributes                        

-------------------+------------------------------------------------------------

app               |

postgres          | Superuser, Create role, Create DB, Replication, Bypass RLS

streaming_replica | Replication

postgres=# \l

                                                List of databases

   Name    |  Owner   | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules |   Access privileges  

-----------+----------+----------+-----------------+---------+-------+--------+-----------+-----------------------

app       | app      | UTF8     | libc            | C       | C     |        |           |

postgres  | postgres | UTF8     | libc            | C       | C     |        |           |

template0 | postgres | UTF8     | libc            | C       | C     |        |           | =c/postgres          +

           |          |          |                 |         |       |        |           | postgres=CTc/postgres

template1 | postgres | UTF8     | libc            | C       | C     |        |           | =c/postgres          +

           |          |          |                 |         |       |        |           | postgres=CTc/postgres

(4 rows)

However, if you don't specify any database options in your CNPG cluster manifest like we did, the operator automatically creates an app user and an app database, with the app user as the owner.

Conclusion

Getting started with CloudNativePG on Minikube is a powerful step toward managing PostgreSQL in a truly cloud - native way. With just one or a few YAML manifest(s) and some basic kubectl commands, we’ve seen how easy it is to deploy a production-grade database system on Kubernetes. From installation to validation and even direct access via psql, CNPG simplifies operations that would traditionally be complex and manual.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4