1. Install Prerequisites
Install Helm, KIND, kubectl, and pgAdmin4.
2. Create KIND Cluster
Run kind create cluster --name myk8s --config cluster.yaml
### cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
3. Deploy CloudNativePG Operator
helm repo add cnpg https://cloudnative-pg.github.io/charts
helm repo update
helm install cnpg cnpg/cloudnative-pg --namespace cnpg-system --create-namespace
4. Deploy PostgreSQL Cluster
Run kubectl apply -f postgres.yaml
## postgres.yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg-cluster
labels:
app: pg
spec:
instances: 3
storage:
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard
volumeMode: Filesystem
postgresql:
parameters:
shared_buffers: 256MB
---
# pgBouncer
apiVersion: postgresql.cnpg.io/v1
kind: Pooler
metadata:
name: pg-pooler
labels:
app: pg
spec:
cluster:
name: pg-cluster
instances: 3
type: rw
serviceTemplate:
metadata:
labels:
app: pg
spec:
type: LoadBalancer
pgbouncer:
poolMode: session
parameters:
max_client_conn: "1000"
default_pool_size: "10"
5. Install Kubernetes Cloud Provider for KIND
- Installation
- Control-plane nodes need to remove the label to access workloads via a LoadBalancer service.
kubectl label node myk8s-control-plane node.kubernetes.io/exclude-from-external-load-balancers-
- Run As administrator
./cloud-provider-kind
6. Connect to PostgreSQL with pgAdmin4
Open pgAdmin4, create a new server with PostgreSQL connection details
- EXTERNAL-IP
kubectl get svc pg-pooler
- Password (pg-cluster-app)
kubectl get secret pg-cluster-app -o yaml
## check data.password
echo <password> | base64 -d
host=<External IP>
port=5432
database=app
user=app
password=<password>
Top comments (0)