image/svg+xml
CYBERTEC-PG-Operator
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage Support

Quickstart

We can tell and document so much about our project but it seems you just want to get started. Let us show you the fastest way to use CPO.

Preconditions

  • git
  • helm (optional)
  • kubectl or oc

Let’s start

Step 1 - Preparations

To get started, you can fork our tutorial repository on Github and then download it. CYBERTEC-operator-tutorials

git clone https://github.com/cybertec-postgresql/CYBERTEC-operator-tutorials.git
cd CYBERTEC-operator-tutorials

Step 2 - Install the Operator

Two options are available for the installation:

  • Installation via Helm-Chart (local or via helmn-repo)
  • Installation via apply

Installation via Helm-Chart

If you want to use the helm-chart, YOU can decide for yourself whether you want to use the helm-cahrt from the operator-tutorials on github or directly connect the helm-repo for the cpo-project and install the helm-chart over it.

#add helm-repo (optional)
  helm repo add cpo https://cybertec-postgresql.github.io/CYBERTEC-operator-tutorials
  kubectl apply -n cpo -k setup/namespace/.
  helm install -n cpo cpo cpo/postgres-operator

or

# use local helm-chart from git
  kubectl apply -n cpo -k setup/namespace/.
  helm install cpo -n cpo setup/helm/operator/

Installation via apply

kubectl apply -n cpo -k setup/namespace/.
kubectl apply -n cpo -k setup/helm/operator/.

You can check if the operator pod is in operation.

kubectl get pods -n cpo --selector=cpo.cybertec.at/pod/type=postgres-operator

The result should look like this:

NAME                                 READY   STATUS    RESTARTS   AGE
postgres-operator-599688d948-fw8pw   1/1     Running   0          41s

The operator is ready and the setup is complete. The next step is the creation of a Postgres cluster

Step 3 - Create a Cluster

To create a simple cluster, the following command is sufficient

kubectl apply -n cpo -f cluster-tutorials/single-cluster
watch kubectl get pods -n cpo --selector cluster-name=cluster-1

The result should look like this:

Alle 2.0s: kubectl get pods -n cpo --selector cluster-name=cluster-1                                                                                                            

NAME          READY   STATUS            RESTARTS   AGE
cluster-1-0   2/2     Running           0          28s
cluster-1-1   0/2     PodInitializing   0          9s

Step 4 - Connect to the Database

Get your login information from the secret.

kubectl get secret -n cpo postgres.cluster-1.credentials.postgresql.cpo.opensource.cybertec.at -o jsonpath='{.data}' | jq '.|map_values(@base64d)'

The result should look like this:

{
  "password": "2rZG1Kx9asdHscswQGzff4Ru0xW6uasacy3GQ0sjdCH3wWr0kguUXUZek6dkemsf",
  "username": "postgres"
}

Connection via port-forward

kubectl port-forward -n cpo cluster-1-0 5432:5432
# using psql
PGPASSWORD=2rZG1Kx9asdHscswQGzffjdCH3wWr0kguUXUZek6dkemsf psql -h 127.0.0.1 -p 5432 -U postgres

# using usql
PGPASSWORD=2rZG1Kx9asdHscswQGzffjdCH3wWr0kguUXUZek6dkemsf usql postgresql://postgres@127.0.0.1/postgres

Next Steps

Congratulations, your first cluster is ready and you were able to connect to it. On the following pages we have put together an introduction with lots of information and details to show you the different possibilities and components of CPO.