Skip to main content

Command Palette

Search for a command to run...

🚀 Deploying Nginx + Redis on Kubernetes Using a Custom Helm Chart (Full Guide)

Updated
4 min read

This post walks you through building a complete Helm chart that deploys:

  • Nginx (frontend)
  • Redis (backend)
  • With Bitnami Redis as a dependency
  • Includes hooks, schema validation, and packaging
  • And finally, pushing the packaged chart to Azure Container Registry (ACR)

Perfect for anyone learning Helm or preparing for DevOps interviews.


📌 What You Will Build

A fully working Kubernetes deployment using:

  • A top-level Helm chart (nginx-redis-chart)
  • A Redis subchart (Bitnami)
  • Custom templates for Nginx Deployment + Service
  • A pre-install hook job
  • A JSON schema validator
  • A packaged .tgz Helm artifact published to ACR

🧰 Prerequisites (Windows Setup)

  • Install Helm:

    choco install kubernetes-helm
    
  • Install Minikube:

    winget install Kubernetes.minikube
    
  • Enable virtualization → install Docker Desktop

  • Start Minikube:

    minikube start --driver=docker
    
  • Verify:

    kubectl get nodes
    helm version
    

📁 Step 1 — Create the Helm Chart

helm create nginx-redis-chart
cd nginx-redis-chart

This generates:

Chart.yaml
values.yaml
templates/
charts/

📦 Step 2 — Add Redis Dependency

Add Bitnami Redis to Chart.yaml:

dependencies:
  - name: redis
    version: 19.0.0
    repository: "https://charts.bitnami.com/bitnami"

Update dependencies:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm dependency update .

This pulls Redis into charts/redis-*.tgz.


⚙️ Step 3 — Configure values.yaml

replicaCount: 2

image:
  repository: nginx
  tag: stable
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80
  targetPort: 80

redis:
  enabled: true
  fullnameOverride: redis
  architecture: standalone
  usePassword: false

🧱 Step 4 — Create Nginx Deployment

templates/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "nginx-redis-chart.fullname" . }}-nginx
  labels:
    app: {{ include "nginx-redis-chart.name" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ include "nginx-redis-chart.name" . }}
  template:
    metadata:
      labels:
        app: {{ include "nginx-redis-chart.name" . }}
    spec:
      containers:
        - name: nginx
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - containerPort: {{ .Values.service.targetPort }}
          env:
            - name: REDIS_HOST
              value: {{ printf "%s-redis-master" (include "nginx-redis-chart.fullname" .) | quote }}

🌐 Step 5 — Create Nginx Service

templates/service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: {{ include "nginx-redis-chart.fullname" . }}-svc
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: {{ .Values.service.targetPort }}
  selector:
    app: {{ include "nginx-redis-chart.name" . }}

🪝 Step 6 — Pre-install Hook Job

templates/preinstall-job.yaml:

apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ include "nginx-redis-chart.fullname" . }}-preinstall"
  annotations:
    "helm.sh/hook": pre-install
    "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
  template:
    spec:
      restartPolicy: Never
      containers:
        - name: preinstall
          image: bitnami/kubectl:latest
          command: ["sh","-c","echo Pre-install hook executed"]

🧪 Step 7 — Add JSON Schema Validation

Create values.schema.json:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "replicaCount": { "type": "integer", "minimum": 1 },
    "image": {
      "type": "object",
      "properties": {
        "repository": { "type": "string" },
        "tag": { "type": "string" }
      }
    },
    "service": {
      "type": "object",
      "properties": {
        "type": { "type": "string", "enum": ["ClusterIP","NodePort","LoadBalancer"] },
        "port": { "type": "integer" },
        "targetPort": { "type": "integer" }
      }
    },
    "redis": { "type": "object" }
  }
}

Validate:

helm lint .

🚀 Step 8 — Install the Chart

helm install my-nginx . -n test --create-namespace

Check resources:

kubectl get all -n test

You’ll see:

  • Redis StatefulSet + Pod
  • Nginx Deployment (2 pods)
  • Services for Redis and Nginx

📦 Step 9 — Package the Chart

helm package .

Produces:

nginx-redis-chart-0.1.0.tgz

☁️ Step 10 — Push to Azure Container Registry (ACR)

1️⃣ Login to ACR

az login
az acr login --name <acr-name>

2️⃣ Push Helm chart to ACR

helm push nginx-redis-chart-0.1.0.tgz oci://<acr-name>.azurecr.io/helm

3️⃣ Verify

az acr repository list --name <acr-name> --output table

4️⃣ Install from ACR

helm install my-nginx oci://<acr-name>.azurecr.io/helm/nginx-redis-chart --version 0.1.0

🎉 Final Thoughts

You now have:

  • A complete custom Helm chart
  • Redis subchart integration
  • A working Nginx + Redis deployment
  • Schema validation
  • Helm hooks
  • Packaged chart
  • Pushed to Azure Container Registry

This is a fully production-style Helm workflow, excellent for DevOps learning and interviews.


More from this blog

Vinay206

10 posts