Bitnami is a company that provides pre-packaged software stacks for popular open source applications(Belong the VMware Sub-company).
Here are some of the benefits of using Bitnami stacks:
- Easy to install and use
- Regularly updated with security patches and bug fixes
- Available for a variety of platforms
- Wide range of applications available
- Community support
So we are install the postgresql to Huaweicloud CCE platform (A famous k8s commercial platform ) today .
1. Install the helm3
Note: we need install the newest version from helm official website , we cannot use the huaweicloud official document (the website offer the old helm version , there will be have the error Error: parse error at (postgresql/templates/_helpers.tpl:164): unclosed action
)
Install helm command like this:
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
# or one line command like this:
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
2. helm3 install PostgreSQL
The new helm use oci install the application , let’s try use the below command:
helm install my-release oci://registry-1.docker.io/bitnamicharts/postgresql
But when we check the install result, we found the application install failed. Use the command kubectl get PVC
and kubectl get events
get the detail information, we know the failed reason is there didn’t have the available PVC and PV for use.
3. helm3 add the parameters
We can checked the parameters in the artifacthub. some parameters like this:
--set primary.persistence.existingClaim=postgres-pvc \
--set volumePermissions.enabled=true \
--set global.postgresql.auth.postgresPassword={your-postgres-admin-password} \
--set global.postgresql.auth.username={your-postgres-username} \
--set global.postgresql.auth.password={your-postgres-password} \
--set global.postgresql.auth.database={your-postgres-database}
And we can also use the helm show command see the details values setting.
helm show values oci://registry-1.docker.io/bitnamicharts/postgresql > values.yaml
We can edit values.yaml file, use helm install pgdatabase oci://registry-1.docker.io/bitnamicharts/postgresql -f values.yaml
command install also.
4. Start from begins
a. Create dynamic PVC
Edit a dynamic PVC yaml file:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pg-data-pvc
namespace: default
labels:
app: pg-data-pvc
spec:
storageClassName: csi-disk
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
Create PVC and PV:
kubectl apply -f pg-pvc.yaml
b. Install postgresql use helm
helm install pgdatabase oci://registry-1.docker.io/bitnamicharts/postgresql \
--set primary.persistence.existingClaim=pg-data-pvc \
--set volumePermissions.enabled=true \
--set global.postgresql.auth.postgresPassword={your-postgres-admin-password} \
--set global.postgresql.auth.username={your-postgres-username} \
--set global.postgresql.auth.password={your-postgres-password} \
--set global.postgresql.auth.database={your-postgres-database}
c. Check the install result
[root@testcce-92497 ~]# kubectl apply -f pg-pvc.yaml
persistentvolumeclaim/pg-data-pvc created
[root@testcce-92497 ~]# helm install pgdatabase oci://registry-1.docker.io/bitnamicharts/postgresql \
--set primary.persistence.existingClaim=pg-data-pvc \
--set volumePermissions.enabled=true \
--set global.postgresql.auth.postgresPassword=mypgpasswd
[root@testcce-92497 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pgdatabase-postgresql-0 1/1 Running 0 35s
[root@testcce-92497 ~]# kubectl exec -it pgdatabase-postgresql-0 -- /bin/bash
Defaulted container "postgresql" out of: postgresql, init-chmod-data (init)
I have no name!@pgdatabase-postgresql-0:/$ PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -d postgres -p 5432
psql (15.3)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+-------------+-------------+------------+-----------------+------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres+ |
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres + |
(3 rows)
5. Create master/standby Postgresql
This helm charts support master/standby architecture. primary.standby.enabled
set true is open this function, and set the readReplicas.persistence.existingClaim
for slave node persistence disk, set the architecture
to replication
.
a. create PersistentVolumeClaim for master/standby
[root@testcce-92497 pg]# cat primary.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-pgdatabase-postgresql-primary-0
namespace: default
labels:
app: data-pgdatabase-postgresql-primary-0
spec:
storageClassName: csi-disk
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
[root@testcce-92497 pg]# cat read-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-pgdatabase-postgresql-read-0
namespace: default
labels:
app: data-pgdatabase-postgresql-read-0
spec:
storageClassName: csi-disk
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
[root@testcce-92497 pg]# kubectl apply -f primary.yaml -f read-pvc.yaml
persistentvolumeclaim/data-pgdatabase-postgresql-primary-0 created
persistentvolumeclaim/data-pgdatabase-postgresql-read-0 created
b. create master/standby architecture
use the blow command for create the postgresql:
helm install pgdatabase oci://registry-1.docker.io/bitnamicharts/postgresql \
--set primary.persistence.existingClaim=data-pgdatabase-postgresql-primary-0 \
--set volumePermissions.enabled=true \
--set global.postgresql.auth.postgresPassword=mypgpasswd \
--set architecture=replication \
--set readReplicas.persistence.existingClaim=data-pgdatabase-postgresql-read-0
c. verify the result
Ensure the pods,statefulset,service is successful:
[root@testcce-92497 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pgdatabase-postgresql-primary-0 1/1 Running 0 14m
pgdatabase-postgresql-read-0 1/1 Running 0 14m
[root@testcce-92497 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.247.0.1 <none> 443/TCP 2d6h
pgdatabase-postgresql-primary ClusterIP 10.247.237.128 <none> 5432/TCP 7m6s
pgdatabase-postgresql-primary-hl ClusterIP None <none> 5432/TCP 7m6s
pgdatabase-postgresql-read ClusterIP 10.247.162.25 <none> 5432/TCP 7m6s
pgdatabase-postgresql-read-hl ClusterIP None <none> 5432/TCP 7m6s
[root@testcce-92497 ~]# kubectl get sfs
error: the server doesn't have a resource type "sfs"
[root@testcce-92497 ~]# kubectl get sts
NAME READY AGE
pgdatabase-postgresql-primary 1/1 7m23s
pgdatabase-postgresql-read 1/1 7m23s
create a test database in master node, check in the standy read database.