Kubernetes Introduction

Nathan Luong | April 15, 2024 12

What is K8S

  • Open-source container orchestration tool
  • Developed by Google
  • With Increased usage of containers, demanding for a proper way of managing those hundreds of containers

Features

  • High Availability
  • Salability
  • Disaster Recovery → Backup and restore

K8S Components

K8S Components

Node

  • Simple a server, a physical machine, or a VM

Pod

  • The smallest unit of K8S
  • Abstraction over container
  • Pods are meant to run only 1 container within it, 1 app/pod
  • Each pod is assigned an IP address
  • Pods communicate with each others using IP address
  • Pods can die easily → When pods die, they got assigned a new IP on creation

Service

  • Permanent IP address that can be attached to each pod
  • Lifecycle of Pod and Service are not connected
  • External Service: Exposed its communication to external sources
  • Internal Service: Not exposed to the world

ℹ️

A service can be a Load Balancer

Ingress

  • Forward requests to Services

Config Map

  • external configuration of the application

Don’t put username and password on Config Map

Secrets

  • Used to store secret data
  • Base64 encoded

The built-in security is not enabled by default!

Volumes

  • Attaches a storage onto the pod
  • The storage can be local or remote (outside of the K8S cluster like cloud or on-premise)
  • K8S doesn’t manage data persistence

Deployment

K8S Deployment
  • blueprint for my-app pods
  • Database can’t be replicate via deployment

StatefulSet

K8S StatefulSet
  • Deploys for stateful Apps or Databases

K8S Architecture

Worker Machine in K8S cluster

  • Each Node has multiple Pods on it
  • 3 processes must be installed on every Node
  • Worker Nodes do the actual work

Container runtime (Docker) is installed on all nodes

  • kubelet
    • Processes that schedules the pods
    • It interacts with both the container and node
  • Nodes are communicate via Services
  • Kube Proxy:
    • Must be installed on every Nodes
    • Forwards the requests to the nodes
    • Making sure that the performance is performing with the lowest overheads

Master Processes

Master-Processes
  • Have 4 processed that run on every master node
    1. API Server
      • Cluster Gateway
      • Client interact with the API Server to create/manage new applications
      • Act as a validator which authenticate the Client Requests
    2. Scheduler
      • Decide which of the worker node to put the pod in
      • See how much resources the application that client want to schedule will need (how much CPU, RAM)
      • Choose the Node to schedule it in via Kubelet
    3. Controller Manager
      • When a pod dies on any Node, The Controller Manager request the Scheduler to recover the pods
    4. etcd
      • The cluster Brain.
      • Cluster changes get stored in the key value store.
  • Master Nodes consumes less resources (CPU, RAM, Storage)

Example Cluster Set-Up

Add new Master/Node server

Master-Node-server
  1. Get new bare server
  2. Install all the master/worker node processes
  3. Add it to the cluster