Helm Chart That Deploys Your Application

Helm Chart That Deploys Your Application

A helm chart that deploys your application which utilizes the following Kubernetes objects: ● Deployments ● Service ● K8s Secrets

Overview

This post outlines the steps and configurations for deploying an application using Helm, a Kubernetes package manager. The application is configured to utilize a postgreSQL database for data storage/ The Helm chart includes specifications for Deployments, Services, Secrets and a PostgreSQL dependency.

Technologies Used

Kubernetes, Docker, Helm, K8s cluster – minikube, YAML

Procedure:

Create a directory for the Helm chart and define all the necessary files such as values.yaml; Chart.yaml

  • “Chart.yaml”:-

This directory will hold all the files required to define and deploy the application.

apiVersion: v2
name: my-app-chart
description: A Helm chart to deploy an application with PostgreSQL database and secrets
version: 0.1.0


dependencies:
  - name: postgresql
    version: X.X.X  
    repository: https://charts.bitnami.com/bitnami
  • “values.yaml”:

The values.yaml file holds customizable parameters for your Helm chart. These values can be used throughout your chart's templates to configure various aspects of your application and infrastructure. Here, you set values such as the number of replicas for your application and PostgreSQL database credentials. This separation of configuration from templates enables easy customization without modifying the actual templates.

# You can define any other values specific to your application here
database:
  username: myuser
  password: mysecretpassword
  name: mydb
  port: 5432

replicaCount: 2

The templates directory contains YAML files that define Kubernetes resources. Each resource corresponds to a component of your application. In this step, you created three template files:

  • “deployment.yaml”:

Defines a Kubernetes Deployment resource for managing application replicas and updates.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-deployment
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app-container
          image: your/app-image:latest
          env:
            - name: DB_HOST
              value: my-app-db-service
            - name: DB_PORT
              value: "5432"
            - name: DB_NAME
              value: {{ .Values.database.name }}
            - name: DB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: my-db-secrets
                  key: username
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: my-db-secrets
                  key: password
          ports:
            - containerPort: 80
  • “service.yaml”: Defines a Kubernetes Service resource that enables communication with your application pods.
apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  • “secrets.yaml”: Defines a Kubernetes Secret resource to securely store and manage sensitive data, such as database credentials.
apiVersion: v1
kind: Secret
metadata:
  name: my-db-secrets
type: Opaque
data:
  username: {{ .Values.database.username | b64enc | quote }}
  password: {{ .Values.database.password | b64enc | quote }}

Helm uses template rendering to inject values from your values.yaml file into these resource definitions. This dynamic configuration allows you to create reusable templates that adapt to specific deployment requirements.

By running “helm dependency build”, Helm fetches the necessary chart dependencies and stores them in a local cache. This step prepares your Helm chart for deployment by making sure all dependencies are available. This step prepares your Helm chart for deployment by making sure all dependencies are available.

Installation of the Helm Chart:-

With all the necessary configurations and dependencies in place, you're ready to deploy your application using Helm. The “helm install” command initiates the deployment process. You specify a release name (‘my-app’ in this case) and provide the path to the directory containing your Helm chart (. represents the current directory). Helm then takes care of deploying your application, including the PostgreSQL database as defined in the dependency.

Conclusion:-

Deploying applications with Helm provides a structured and efficient approach to managing complex deployments on Kubernetes. By defining configuration values, templates, and dependencies, you create a repeatable and scalable deployment process. This document guides you through each step, from setting up the chart directory to deploying the Helm chart, ensuring that your application and its PostgreSQL database are ready to serve users reliably.

Checkout my DevOps Github repo for reference.