rrrr
rrrr

Reputation: 105

how to create helm chart of postgres with pvc

I would like to create a helm chart for PostgreSQL with PVC (persistent volume claim).

I've looked at trying katacoda https://www.katacoda.com/courses/kubernetes/helm-package-manager Create Postgres helm chart with pvc.

How might I do this?

Upvotes: 7

Views: 31208

Answers (4)

Raimundas Rimkus
Raimundas Rimkus

Reputation: 1

Only with these parameters will work:

helm install <my-release> bitnami/postgresql \
  --set primary.persistence.enabled=true \ 
  --set primary.persistence.existingClaim=postgres-pv-claim \
  --set primary.persistence.storageClass=<storageClassName> \
  --set volumePermissions.enabled=true

Upvotes: 0

Math
Math

Reputation: 818

this https://arctype.com/blog/deploy-postgres-kubernetes/ solve my issues

# clean
helm list
helm delete postgresql-db
helm repo remove bitnami
kubectl get pvc
kubectl delete pvc data-postgresql-db
helm repo add bitnami https://charts.bitnami.com/bitnami
helm search repo postgresql

# Create PV & PVC
echo "---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgresql-pv
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
" > pv.yaml
k apply -f pv.yaml

echo "---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgresql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
" > pvc.yaml
k apply -f pvc.yaml

helm install postgresql-db bitnami/postgresql --set persistence.existingClaim=postgresql-pv-claim --set volumePermissions.enabled=true

Upvotes: 1

Crou
Crou

Reputation: 11428

As we can read from PostgreSQL helm charts docs it can be used with following parameters:

+----------------------------+-----------------------------------------------------------------+---------------+
|         Parameter          |                           Description                           |    Default    |
+----------------------------+-----------------------------------------------------------------+---------------+
| persistence.enabled        | Enable data persistence                                         | true          |
| persistence.existingClaim  | Use a existing PVC which must be created manually before bound  | nil           |
| persistence.storageClass   | Specify the storageClass used to provision the volume           | nil           |
| persistence.mountPath      | Path to mount data volume at                                    | nil           |
| persistence.accessMode     | Access mode of data volume                                      | ReadWriteOnce |
| persistence.size           | Size of data volume                                             | 8Gi           |
| persistence.annotations    | Persistent Volume Claim annotations                             | {}            |
+----------------------------+-----------------------------------------------------------------+---------------+

Persistence

The data is persisted by default using PVC templates in the PostgreSQL statefulset. You can disable the persistence setting the persistence.enabled parameter to false. A default StorageClass is needed in the Kubernetes cluster to dynamically provision the volumes. Specify another StorageClass in the persistence.storageClass or set persistence.existingClaim if you have already existing persistent volumes to use.

This means you just need to create your own Persistent Volume which can for example look like this:

pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi

Once those are deployed and bounded you can install the PostgreSQL chart:

helm install my-release bitnami/postgresql --set persistence.existingClaim=task-pv-claim

Upvotes: 7

Tek Nath
Tek Nath

Reputation: 1789

I deployed using following PVC ,values.yaml and Chart.yaml

pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 25Gi

values.yaml

postgresql:
  cpu: 1000m
  memory: 1Gi
  persistence:
    enabled: true
    existingClaim: postgres-pvc
  volumePermissions:
    enabled: true
  replication:
    enabled: false
  initdbScripts:
    psql.sql: |
      CREATE USER user WITH PASSWORD 'pass';
      ALTER USER user WITH SUPERUSER;

Chart.yaml

apiVersion: v2
name: pgname
description: A Short description

type: application

version: 0.1.3

appVersion: 1.16.2

dependencies:
  - name: postgresql
    version: 7.x.x
    repository: https://kubernetes-charts.storage.googleapis.com/
    condition: postgresql.enabled
    tags:
      - services
      - db
      - write

I have got above files in following directory structure.

.
├── Chart.yaml
├── charts
│   └── postgresql-7.7.3.tgz
└── values.yaml

At . I do helm dependency update and helm install release_name . to install. Before that kubectl apply -f pvc.yaml

Note You Need to in in same namespace

Upvotes: 6

Related Questions