0
0
Kubernetesdevops~30 mins

Database operators example in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Database Operators Example with Kubernetes
📖 Scenario: You are working as a DevOps engineer managing a Kubernetes cluster. Your team wants to deploy a PostgreSQL database using a Kubernetes Operator to simplify management tasks like backups and scaling.
🎯 Goal: Learn how to deploy a PostgreSQL database using a Kubernetes Operator by creating the necessary Kubernetes manifests step-by-step.
📋 What You'll Learn
Create a namespace for the database operator
Deploy the PostgreSQL Operator in the namespace
Create a PostgreSQL cluster custom resource
Verify the PostgreSQL pods are running
💡 Why This Matters
🌍 Real World
Kubernetes Operators automate complex application management tasks like deploying and managing databases in cloud environments.
💼 Career
DevOps engineers and SREs use Operators to simplify database lifecycle management, improving reliability and reducing manual work.
Progress0 / 4 steps
1
Create a namespace for the PostgreSQL Operator
Write a YAML manifest to create a Kubernetes namespace called postgres-operator. Use the apiVersion v1 and kind Namespace.
Kubernetes
Need a hint?

Namespaces isolate resources in Kubernetes. Use apiVersion: v1 and kind: Namespace with metadata name.

2
Deploy the PostgreSQL Operator in the namespace
Write a YAML manifest to deploy the PostgreSQL Operator as a Deployment named postgres-operator in the postgres-operator namespace. Use apps/v1 for apiVersion and specify 1 replica. Use the container image postgres-operator:latest.
Kubernetes
Need a hint?

Deployments manage pods. Use apps/v1 apiVersion, set replicas to 1, and specify the container image.

3
Create a PostgreSQL cluster custom resource
Write a YAML manifest for a PostgreSQL cluster custom resource named example-cluster in the postgres-operator namespace. Use apiVersion: postgres-operator.crunchydata.com/v1beta1 and kind: PostgresCluster. Set instances replicas to 1 and image to postgres:14.
Kubernetes
Need a hint?

Custom resources define the database cluster. Use the correct apiVersion and kind, set replicas and image as specified.

4
Verify the PostgreSQL pods are running
Run the command kubectl get pods -n postgres-operator to list pods in the postgres-operator namespace. Confirm that the pod for example-cluster is in the Running state.
Kubernetes
Need a hint?

Use kubectl get pods -n postgres-operator to see pods and their status.