Lesson 8 / 10
Module 8Lesson 1⏱ 50 min study

Lesson 8: Helm Package Management & Cluster Operations

Automate Helm chart releases, deploy full-stack Prometheus and Grafana monitoring, and execute safe zero-downtime node drain workflows.

✦ Key Architectural Takeaways
  • •Helm acts as the package manager for Kubernetes, packaging complex multi-resource applications into versioned, reproducible charts.
  • •Ansible's kubernetes.core.helm module provides declarative release management, custom values injection, and automated rollback triggers.
  • •Deploying Prometheus and Grafana via automated playbooks establishes continuous metrics collection and alert evaluation.
  • •Zero-downtime node maintenance requires cordoning nodes, evicting workloads via the Eviction API, and respecting PodDisruptionBudgets.
  • •Live in-place modifications can be applied idempotently using JSON Patch or Strategic Merge Patch operations.

1. The Helm Package Manager & Ansible Orchestration

Helm is a graduated CNCF project that packages related Kubernetes resources into versioned bundles called Charts:

  • `Chart.yaml`: Metadata declaring chart name, version, and dependencies.
  • `values.yaml`: Default configuration variables.
  • `templates/`: Jinja2-style Go templates rendered into Kubernetes manifests.

Ansible's kubernetes.core.helm module allows platform engineers to manage Helm chart lifecycles declaratively:

YAMLSYSTEM SCHEMATIC
- name: Deploy Redis Cache Cluster via Official Bitnami Helm Chart
  kubernetes.core.helm:
    name: redis-cluster
    chart_ref: oci://registry-1.docker.io/bitnamicharts/redis
    release_namespace: cache-tier
    create_namespace: true
    state: present
    values:
      architecture: replication
      auth:
        enabled: true
        password: "{{ vault_redis_password }}"
      replica:
        replicaCount: 3
        persistence:
          enabled: true
          size: 10Gi
§

2. Deploying a Cloud-Native Observability Stack

A production Kubernetes cluster requires comprehensive telemetry: metrics, logs, and alerts.

ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
Applications & Nodes
         | (Prometheus Scrape via ServiceMonitor)
         v
+-----------------------------------------------------------------+
| Prometheus Time-Series Database                                 |
| - Collects CPU, memory, network, and custom app metrics         |
| - Evaluates PromQL alerting rules                               |
+-----------------------------------------------------------------+
         |
         +--------------------------------+
         |                                |
         v                                v
+-----------------------+     +-----------------------------------+
| Alertmanager          |     | Grafana Dashboards                |
| (Dispatches alerts    |     | (Visualizes cluster topology,     |
|  to Slack / PagerDuty)|     |  pod health, and traffic spikes)  |
+-----------------------+     +-----------------------------------+

Using Ansible, deploying the entire kube-prometheus-stack Helm chart (Prometheus Operator, Grafana, Alertmanager, node-exporter) requires a single declarative task:

YAMLSYSTEM SCHEMATIC
- name: Deploy Complete Kube-Prometheus Observability Stack
  kubernetes.core.helm:
    name: kube-prometheus-stack
    chart_repo_url: https://prometheus-community.github.io/helm-charts
    chart_ref: kube-prometheus-stack
    release_namespace: monitoring
    create_namespace: true
    state: present
    values:
      grafana:
        adminPassword: "{{ vault_grafana_password }}"
      prometheus:
        prometheusSpec:
          retention: 30d
          storageSpec:
            volumeClaimTemplate:
              spec:
                resources:
                  requests:
                    storage: 50Gi
§

3. Zero-Downtime Node Maintenance Workflows

Performing kernel upgrades or hardware maintenance on worker nodes must never disrupt running services. Ansible automates the safe three-stage maintenance routine:

ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
Stage 1: Cordon Node                Stage 2: Drain Pods
[ Node marked unschedulable ] ----> [ Evicts pods via Eviction API; ]
(New pods will not land here)       [ respects PodDisruptionBudgets ]
                                                   |
                                                   v
Stage 3: Upgrade & Uncordon          [ Pods reschedule safely onto  ]
[ Host patched, rebooted,    ] <--- [ neighboring healthy nodes    ]
[ marked schedulable again   ]

Ansible Node Drain Playbook

YAMLSYSTEM SCHEMATIC
---
- name: Safely Drain and Upgrade Kubernetes Worker Node
  hosts: localhost
  connection: local
  vars:
    target_node: "worker-node-03"

  tasks:
    - name: Cordon Node (Mark Unschedulable)
      kubernetes.core.k8s_drain:
        name: "{{ target_node }}"
        state: cordon

    - name: Drain Pods Safely Using the Eviction API
      kubernetes.core.k8s_drain:
        name: "{{ target_node }}"
        state: drain
        delete_emptydir_data: true
        ignore_daemonsets: true
        force: false # Enforces PodDisruptionBudget limits!

    - name: Execute Host OS Kernel Patching via SSH
      ansible.builtin.command: "ssh root@{{ target_node }} 'apt-get update && apt-get dist-upgrade -y && reboot'"
      async: 600
      poll: 0

    - name: Wait for Node to Recover and Return to Ready State
      kubernetes.core.k8s_info:
        kind: Node
        name: "{{ target_node }}"
      register: node_status
      until: "node_status.resources[0].status.conditions | selectattr('type', 'equalto', 'Ready') | map(attribute='status') | first == 'True'"
      retries: 30
      delay: 10

    - name: Uncordon Node (Resume Normal Scheduling)
      kubernetes.core.k8s_drain:
        name: "{{ target_node }}"
        state: uncordon