Postgres
This guide will walk you through the steps to add a PostgreSQL database to an existing Helm chart for your Kubernetes application. Helm charts help manage Kubernetes applications using templates, and adding PostgreSQL will involve integrating the Bitnami PostgreSQL Helm chart as a dependency and configuring it appropriately.
Stepsβ
1. Add PostgreSQL Helm Repositoryβ
First, add the Bitnami repository, which hosts the PostgreSQL Helm chart,
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
2. Update Chart.yaml
β
Open your existing Helm chart directory and edit the Chart.yaml file to add PostgreSQL as a dependency,
# Chart.yaml
apiVersion: v2
name: your-app
description: A Helm chart for your Kubernetes application
version: 0.1.0
appVersion: '1.0'
dependencies:
- name: postgresql
version: 12.1.9
repository: https://charts.bitnami.com/bitnami
3. Update values.yaml
β
Create or update the values.yaml file to include configuration values for PostgreSQL. You can customize the values based on your requirements.
# values.yaml
postgresql:
enabled: true
global:
postgresql:
auth:
postgresqlPassword: mysecretpassword
primary:
persistence:
enabled: true
size: 8Gi
4. Install/Update Dependenciesβ
Navigate to your Helm chart directory and run the following command to update dependencies,
helm dependency update
5. Update Your Application Deploymentβ
Modify your applicationβs deployment files to include the PostgreSQL service. Ensure your application can connect to PostgreSQL using the service name and credentials specified in the values.yaml
file.
For example, if using a ConfigMap to store environment variables for your application, you might update it like this,
# templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: your-app-config
data:
DATABASE_HOST: 'your-app-postgresql'
DATABASE_PORT: '5432'
DATABASE_USER: 'postgres'
DATABASE_PASSWORD: 'mysecretpassword'
DATABASE_NAME: 'yourdbname'
6. Deploy Your Applicationβ
Finally, deploy or upgrade your application using Helm,
helm install your-app ./your-app-chart
# or if upgrading an existing release
helm upgrade your-app ./your-app-chart
7. Verify Deploymentβ
Check the status of your Helm release to ensure everything is running correctly,
helm status your-app
Also, verify that the PostgreSQL pod is running,β
kubectl get pods
You should see a pod for PostgreSQL, something like your-app-postgresql-0
.
Congratulations! You have successfully added PostgreSQL to your existing Helm chart. This integration allows your application to use PostgreSQL as its database, managed efficiently with Helm. You can further customize the PostgreSQL configuration by modifying the values.yaml file as needed.