Skip to content

Install Percona Distribution for PostgreSQL using kubectl

A Kubernetes Operator is a special type of controller introduced to simplify complex deployments. The Operator extends the Kubernetes API with custom resources.

The Percona Operator for PostgreSQL is based on best practices for configuration and setup of a Percona Distribution for PostgreSQL cluster in a Kubernetes-based environment on-premises or in the cloud.

We recommend installing the Operator with the kubectl command line utility. It is the universal way to interact with Kubernetes. Alternatively, you can install it using the Helm package manager.

Install with kubectl Install with Helm

Prerequisites

To install Percona Distribution for PostgreSQL, you need the following:

  1. The kubectl tool to manage and deploy applications on Kubernetes, included in most Kubernetes distributions. Install not already installed, follow its official installation instructions .

  2. A Kubernetes environment. You can deploy it on Minikube for testing purposes or using any cloud provider of your choice. Check the list of our officially supported platforms.

Procedure

Here’s a sequence of steps to follow:

  1. Create the Kubernetes namespace for your cluster. It is a good practice to isolate workloads in Kubernetes by installing the Operator in a custom namespace. For example, let’s name it postgres-operator:

    $ kubectl create namespace postgres-operator
    
    Expected output
    namespace/postgres-operator was created
    

    We will use this namespace further on in this document. If you used another name, make sure to replace it in the following commands.

  2. Deploy the Operator using the following command:

    $ kubectl apply --server-side -f https://raw.githubusercontent.com/percona/percona-postgresql-operator/v2.5.0/deploy/bundle.yaml -n postgres-operator
    
    Expected output
    customresourcedefinition.apiextensions.k8s.io/crunchybridgeclusters.postgres-operator.crunchydata.com serverside-applied
    customresourcedefinition.apiextensions.k8s.io/perconapgbackups.pgv2.percona.com serverside-applied
    customresourcedefinition.apiextensions.k8s.io/perconapgclusters.pgv2.percona.com serverside-applied
    customresourcedefinition.apiextensions.k8s.io/perconapgrestores.pgv2.percona.com serverside-applied
    customresourcedefinition.apiextensions.k8s.io/perconapgupgrades.pgv2.percona.com serverside-applied
    customresourcedefinition.apiextensions.k8s.io/pgadmins.postgres-operator.crunchydata.com serverside-applied
    customresourcedefinition.apiextensions.k8s.io/pgupgrades.postgres-operator.crunchydata.com serverside-applied
    customresourcedefinition.apiextensions.k8s.io/postgresclusters.postgres-operator.crunchydata.com serverside-applied
    serviceaccount/percona-postgresql-operator serverside-applied
    role.rbac.authorization.k8s.io/percona-postgresql-operator serverside-applied
    rolebinding.rbac.authorization.k8s.io/service-account-percona-postgresql-operator serverside-applied
    deployment.apps/percona-postgresql-operator serverside-applied
    

    At this point, the Operator Pod is up and running.

  3. Deploy Percona Distribution for PostgreSQL cluster:

    $ kubectl apply -f https://raw.githubusercontent.com/percona/percona-postgresql-operator/v2.5.0/deploy/cr.yaml -n postgres-operator
    
    Expected output
    perconapgcluster.pgv2.percona.com/cluster1 created
    
  4. Check the Operator and replica set Pods status.

    $ kubectl get pg -n postgres-operator
    

    The creation process may take some time. When the process is over your cluster obtains the ready status.

    Expected output
    NAME       ENDPOINT                                   STATUS   POSTGRES   PGBOUNCER   AGE
    cluster1   cluster1-pgbouncer.postgres-operator.svc   ready    3          3           143m
    

You have successfully installed and deployed the Operator with default parameters. You can check them in the Custom Resource options reference.

Next steps

Connect to PostgreSQL

Get expert help

If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services. Join K8S Squad to benefit from early access to features and “ask me anything” sessions with the Experts.


Last update: 2024-10-29