DEV Community

Cover image for Kubernetes and Helm Package Manager
Abhishek Yadav
Abhishek Yadav

Posted on

Kubernetes and Helm Package Manager

Introduction

Kubernetes has become the de facto standard for container orchestration, enabling developers to deploy, scale, and manage containerized applications efficiently. However, managing Kubernetes manifests (YAML files) for complex applications can quickly become overwhelming. That’s where Helm, the package manager for Kubernetes, steps in to simplify the process.

What is Kubernetes?

Kubernetes is a powerful open-source platform that automates the deployment, scaling, and management of containerized applications.
The main components of Kubernetes are

  1. Master Node Components
  • API Server: Acts as the gateway for all Kubernetes API requests. It validates and processes REST commands.
  • Controller Manager: Manages controllers (e.g., Node Controller, Deployment Controller) that ensure the desired state of cluster objects.
  • Scheduler: Assigns pods to nodes based on resource availability and scheduling policies.
  • etcd: A key-value store that holds the cluster's state and configuration data.
  • Worker Node Components
  • Kubelet: Ensures that containers are running in pods.
  • Kube-proxy: Handles networking, including forwarding requests to appropriate pods.
  • Container Runtime: Manages container lifecycle (e.g., Docker, containerd).
  • Workload Objects
  • Pod: The smallest deployable unit; encapsulates containers and shared resources like storage and networking.
  • Service: Exposes pods to the network, ensuring stable connectivity.
  • Deployment: Manages the desired state of pods, supports scaling and rolling updates.
  • ConfigMap & Secret: Provide externalized configurations and secure data, respectively.

What is Helm?

Helm is often called the "Yum or Apt of Kubernetes." It simplifies Kubernetes application deployment by bundling all the manifests into a single reusable package called a chart. With Helm, you can Package all resources (Deployments, Services, ConfigMaps, etc.) into a chart.
Version-control your deployments.
Customize application configurations through values files.
Roll back to previous deployments in case of failure.

Why Use Helm?
Here’s why Helm is a game-changer:

  • Simplified Deployment
    Instead of managing individual YAML files, you use Helm charts that
    organize all resources.

  • Reusability
    Charts can be reused across environments (development, staging,
    production) by overriding values.

  • Ease of Updates
    Helm makes rolling updates and rollbacks straightforward.

  • Consistency
    Standardizes application deployments across teams.

Getting Started with Helm

  1. Install
    Install helm https://helm.sh/docs/intro/install/

  2. Create a Helm Chart
    Use the helm create command to scaffold a new chart:

helm create my-app-deploy
Enter fullscreen mode Exit fullscreen mode

Lets say we want to deploy three services frontend, backend and Redis.
Now we will customise helm chart to deploy these services.

First edit values.yaml file

replicaCount: 1

backend:
  image: sample-backend
  service:
    type: ClusterIP
    port: 8000
  env:
    REDIS_URI: redis://redis-svc:6379

frontend:
  image: sample-frontend
  service:
    type: NodePort
    port: 5173
    nodePort: 31000
  env:
    BACKEND_URL: http://backend-svc:8000

redis:
  image: redis
  service:
    type: ClusterIP
    port: 6379

namespace: default
Enter fullscreen mode Exit fullscreen mode

Now Update Chart.yaml file

apiVersion: v1
name: my-app-deploy
description: A Helm chart for deploying backend, frontend, and redis
version: 1.0.0
appVersion: "1.0.0"
Enter fullscreen mode Exit fullscreen mode

Inside your templates folder update service.yaml file


apiVersion: v1
kind: Service
metadata:
  name: backend-svc
  namespace: {{ .Values.namespace }}
spec:
  type: {{ .Values.backend.service.type }}
  selector:
    app: backend
  ports:
  - protocol: TCP
    port: {{ .Values.backend.service.port }}
    targetPort: {{ .Values.backend.service.port }}

---
apiVersion: v1
kind: Service
metadata:
  name: frontend-svc
  namespace: {{ .Values.namespace }}
spec:
  type: {{ .Values.frontend.service.type }}
  selector:
    app: frontend
  ports:
  - protocol: TCP
    port: {{ .Values.frontend.service.port }}
    targetPort: {{ .Values.frontend.service.port }}
    nodePort: {{ .Values.frontend.service.nodePort }}

---
apiVersion: v1
kind: Service
metadata:
  name: redis-svc
  namespace: {{ .Values.namespace }}
spec:
  type: {{ .Values.redis.service.type }}
  selector:
    app: redis
  ports:
  - protocol: TCP
    port: {{ .Values.redis.service.port }}
    targetPort: {{ .Values.redis.service.port }}

Enter fullscreen mode Exit fullscreen mode

Finally update deployment.yaml


apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-backend
  namespace: {{ .Values.namespace }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
      - name: backend
        image: {{ .Values.backend.image }}
        ports:
        - containerPort: {{ .Values.backend.service.port }}
        env:
        - name: REDIS_URI
          value: {{ .Values.backend.env.REDIS_URI }}

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-frontend
  namespace: {{ .Values.namespace }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: frontend
  template:
    metadata:
      labels:
        app: frontend
    spec:
      containers:
      - name: frontend
        image: {{ .Values.frontend.image }}
        ports:
        - containerPort: {{ .Values.frontend.service.port }}
        env:
        - name: BACKEND_URL
          value: {{ .Values.frontend.env.BACKEND_URL }}

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Chart.Name }}-redis
  namespace: {{ .Values.namespace }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis
        image: {{ .Values.redis.image }}
        ports:
        - containerPort: {{ .Values.redis.service.port }}

Enter fullscreen mode Exit fullscreen mode

Before going further make sure you installed minikube and and it is running properly.
Complete installation guide https://minikube.sigs.k8s.io/docs/start/

Now let's focus on helm

Deploy the Helm Chart

helm install my-app-deploy ./my-app-deploy

Enter fullscreen mode Exit fullscreen mode

Verify deployment

kubectl get deployments
kubectl get services

Enter fullscreen mode Exit fullscreen mode

Check out this repo for reference https://github.com/AIABHISHEK/cosmocloud-deploy

Top comments (0)