There are multiple PostgreSQL Operators listed in the See also section, such as CrunchyDB and Zalando. In this recipe, as an example, we will deploy the Zalando PostgreSQL Operator to manage the life cycle of PostgreSQL Deployments in your Kubernetes cluster.
Let's perform the following steps to get the Zalando PostgreSQL Operator deployed using the Operator Hub:
- Install the postgres-Operator from the Operator Hub:
$ kubectl create -f https://Operatorhub.io/install/postgres-Operator.yaml
- Verify that postgres-Operator is running:
$ kubectl get pods -n Operators
NAME READY STATUS RESTARTS AGE
postgres-Operator-5cd9d99494-5nl5r 1/1 Running 0 3m56s
- Now that the PostgreSQL Operator is up and running, let's deploy the Postgres Operator UI:
$ kubectl apply -f https://raw.githubusercontent.com/k8sdevopscookbook/src/master/chapter2/postgres-Operator/ui/postgres-ui.yaml
- Deploy PostgreSQL. The following command will create a small two-instance PostgreSQL cluster:
$ kubectl create -f https://raw.githubusercontent.com/zalando/postgres-Operator/master/manifests/minimal-postgres-manifest.yaml
- List PostgreSQL instances that are managed by the Zalando Operator. It will show a cluster named acid-minimal-cluster:
$ kubectl get postgresql
NAME TEAM VERSION PODS VOLUME CPU-REQUEST MEMORY-REQUEST AGE STATUS
acid-minimal-cluster acid 11 2 1Gi 7s
- First get your cluster credentials and connect to your PostgreSQL using the psql interactive PostgreSQL terminal as follows:
$ export PGPASSWORD=$(kubectl get secret postgres.acid-minimal-cluster.credentials -o 'jsonpath={.data.password}' | base64 -d)
$ export PGSSLMODE=require
$ psql -U postgres
- Delete your PostgreSQL cluster:
$ kubectl delete postgresql acid-minimal-cluster
Now you have learned how to simply use popular Kubernetes Operators to deploy and manage workloads on Kubernetes. You can apply this knowledge later to simplify the life cycle management of stateful workloads you use in the development and production environment.