Lesson 5 / 10
Module 5Lesson 1⏱ 55 min study

Lesson 5: Declarative Orchestration of Core Workloads

Orchestrate core Kubernetes primitives, decouple configuration with ConfigMaps and Secrets, and configure Layer 4 and Layer 7 network routing.

✦ Key Architectural Takeaways
  • •Namespaces provide logical multi-tenancy, scoped authorization, and resource quota boundaries within a single shared cluster.
  • •Deployments manage declarative rolling updates through underlying ReplicaSets, guaranteeing zero downtime during application upgrades.
  • •ConfigMaps and Secrets decouple runtime configuration from container images in accordance with the Twelve-Factor App methodology.
  • •Services establish stable Layer 4 virtual endpoints across ephemeral Pods via kube-proxy iptables or IPVS connection tracking.
  • •Ingress Controllers provide Layer 7 application routing, SSL/TLS termination, and path-based request multiplexing.

1. Multi-Tenancy Isolation with Namespaces

In production clusters, different teams and environments (Dev, Staging, Production) share cluster compute resources. Namespaces establish logical boundaries:

YAMLSYSTEM SCHEMATIC
- name: Create Namespace with Hard Resource Quotas
  kubernetes.core.k8s:
    state: present
    definition:
      apiVersion: v1
      kind: ResourceQuota
      metadata:
        name: compute-quota
        namespace: production-workloads
      spec:
        hard:
          requests.cpu: "4"
          requests.memory: 8Gi
          limits.cpu: "8"
          limits.memory: 16Gi
          pods: "20"
§

2. Deployments & Zero-Downtime Rolling Updates

A Pod is the smallest deployable computing unit in Kubernetes, wrapping one or more containers that share storage, networking, and IPC namespaces.

However, naked Pods are ephemeral; if a worker node crashes, naked Pods are lost forever. Deployments manage the lifecycle of Pods via ReplicaSets, providing automated self-healing, scaling, and rolling updates:

ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
Deployment Controller (Desired: 3 Replicas)
            |
            v
     ReplicaSet-v1 (Target: 3)
     [ Pod-v1 ]  [ Pod-v1 ]  [ Pod-v1 ]
            |
   (Rolling Update Triggered: image updated to v2)
            v
     ReplicaSet-v1 (Scaled down: 2) <---> ReplicaSet-v2 (Scaled up: 1)
     [ Pod-v1 ]  [ Pod-v1 ]                 [ Pod-v2 ]
            v
     ReplicaSet-v1 (Scaled down: 0) <---> ReplicaSet-v2 (Target: 3)
                                            [ Pod-v2 ]  [ Pod-v2 ]  [ Pod-v2 ]

Rolling Update Parameters:

  • `maxSurge`: Specifies how many Pods can be created above the desired replica count during an update (e.g., 25%).
  • `maxUnavailable`: Specifies how many Pods can be unavailable during the update process (e.g., 0 ensures zero downtime).
§

3. Decoupling Configuration: ConfigMaps & Secrets

The Twelve-Factor App methodology stipulates that application code and configuration must be strictly separated.

  • ConfigMaps: Store non-sensitive configuration keys (JSON configs, environment flags, NGINX configuration files).
  • Secrets: Store sensitive credentials (passwords, API tokens, TLS private keys). By default, Kubernetes Secrets are stored as base64-encoded strings in etcd; production clusters must enable etcd encryption at rest and integrate with external Secret Stores (Vault, AWS Secrets Manager).

Ansible Playbook: Deploying ConfigMap & Secret

YAMLSYSTEM SCHEMATIC
- name: Deploy Application Configuration and Secrets
  kubernetes.core.k8s:
    state: present
    definition:
      - apiVersion: v1
        kind: ConfigMap
        metadata:
          name: app-config
          namespace: production-workloads
        data:
          LOG_LEVEL: "info"
          CACHE_ENABLED: "true"

      - apiVersion: v1
        kind: Secret
        metadata:
          name: app-secrets
          namespace: production-workloads
        type: Opaque
        stringData:
          DATABASE_PASSWORD: "{{ vault_db_password }}"
§

4. Networking: Exposing Workloads via Services & Ingress

Because Pod IP addresses are ephemeral, clients cannot connect directly to Pod IPs. Kubernetes Services provide a stable virtual IP address (ClusterIP) and DNS entry that load-balances traffic across healthy Pod replicas:

ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
Internet Traffic
       |
       v
+-----------------------------------------------------------------+
| Ingress Controller (Layer 7 HTTP/HTTPS Router, TLS Termination) |
| (Routes https://api.example.com to backend-service:8080)        |
+-----------------------------------------------------------------+
       |
       v
+-----------------------------------------------------------------+
| Kubernetes Service: backend-service (ClusterIP: 10.96.120.45)   |
| (Selects Pods matching label: app=backend)                      |
+-----------------------------------------------------------------+
       |
       +------------+------------+
       |                         |
       v                         v
[ Pod: backend-01 ]       [ Pod: backend-02 ]
(IP: 10.244.1.15)         (IP: 10.244.2.22)

Service Types:

  1. 1ClusterIP (Default): Exposes the service on an internal cluster IP. Accessible only within the cluster.
  2. 2NodePort: Allocates a static high-order port (range 30000–32767) on every worker node's physical IP address.
  3. 3LoadBalancer: Integrates with cloud provider APIs (AWS NLB, GCP Network Load Balancer, Azure LB) to provision an external public IP address.
  4. 4Ingress: Manages Layer 7 HTTP/HTTPS traffic routing, SSL/TLS certificates, and hostname/path multiplexing.