📦

Kubernetes Crash Course

Jul 21, 2024

Kubernetes Crash Course by Nana

Introduction

  • Host: Nana
  • Purpose: Teach Kubernetes basics in one hour
  • Taught via: YouTube channel, online courses, DevOps educational program
  • Agenda:
    1. What is Kubernetes and its importance
    2. Kubernetes architecture overview
    3. Main Kubernetes components
    4. Hands-on demo project

What is Kubernetes?

  • Definition: Open-source container orchestration framework developed by Google
  • Manages applications made up of hundreds/thousands of containers
  • Environments: Physical machines, virtual machines, cloud, hybrid

Why Kubernetes?

  • Context: Rise of microservices -> container usage
  • Challenges: Managing many containers across multiple environments is complex
  • Needs: Container orchestration tools required for:
    • High availability: No downtime
    • Scalability: Fast scaling up/down based on load
    • Disaster recovery: Backup and restore capabilities

Kubernetes Architecture

  • Cluster Components: Master Node and Worker Nodes
  • Master Node:
    • API Server: Main entry point for Kubernetes clients (UI, API, CLI)
    • Controller Manager: Handles cluster state and repairs
    • Scheduler: Allocates containers to nodes based on resources and load
    • etcd: Key-value storage holding the cluster state
    • Virtual Network: Enables node communication
  • Worker Nodes:
    • kubelet: Kubernetes process on each node enabling communication
    • Containers: Run the application workload
    • Resources: Typically larger than master node
  • Production: Multiple master nodes for redundancy

Core Kubernetes Components

  • Pod: Smallest unit; abstraction over a container
    • Runs one application container
  • Service: Static IP for Pod communication; internal and external types
  • Ingress: Forwards external requests to services
  • ConfigMap: Stores external configuration data
  • Secret: Stores sensitive information like passwords, certificates
  • Volume: Attaches physical storage to a pod for data persistence
  • Deployment: Manages and scales application pods
  • StatefulSet: Manages stateful applications like databases

Kubernetes Configuration

  • Configuration files in YAML or JSON format
  • API Server: Main entry for configuration requests
  • Example Components: Deployment and Service
  • YAML file structure:
    1. Metadata
    2. Specification
    3. Status (auto-generated)
  • Deployment YAML:
    • Defines replicas, pod template
    • Pod template contains container image, environment variables
  • Service YAML:
    • Defines selector to match pods
    • Ports for service and target

Tools and Setup

  • Minikube: Local Kubernetes cluster with both master and worker processes
    • Install: Various OS, requires Docker as a driver
    • Start: minikube start --driver=docker
    • Status: minikube status
  • kubectl: CLI for interacting with Kubernetes clusters
    • Common commands: kubectl get, kubectl describe, kubectl logs

Hands-On Project

  • Setup: Visual Studio Code
  • Components to deploy:
    1. ConfigMap for MongoDB URL
    2. Secret for MongoDB credentials
    3. Deployment and service for MongoDB
    4. Deployment and service for a web application
  • Example Commands:
    • Create ConfigMap: kubectl apply -f config.yaml
    • Create Secret: kubectl apply -f secret.yaml
    • Deploy MongoDB: kubectl apply -f mongo.yaml
    • Deploy Web App: kubectl apply -f webapp.yaml
  • Accessing Application: minikube ip + NodePort