Kubernetes Core Concepts

Easy 25 min read

What is Kubernetes?

Why Kubernetes Matters

The Problem: Managing containers at scale is complex. You need to handle deployment, scaling, networking, and failures.

The Solution: Kubernetes automates container orchestration, making it easy to deploy and manage containerized applications.

Real Impact: Companies like Google run billions of containers per week using Kubernetes!

Real-World Analogy

Think of Kubernetes as a shipping port manager:

  • Containers = Shipping containers with your goods (applications)
  • Pods = Ships that carry containers
  • Nodes = Docks where ships can park
  • Control Plane = Port authority managing everything
  • Scheduler = Decides which ship goes to which dock

Core Benefits of Kubernetes

Auto-Scaling

Automatically scale your application up or down based on demand. No manual intervention needed.

Self-Healing

Automatically restarts failed containers, replaces and reschedules them when nodes die.

Automated Rollouts

Progressively roll out changes to your application with zero downtime deployments.

Load Balancing

Distributes network traffic so that deployments are stable and performant.

Kubernetes Architecture

Kubernetes Cluster Architecture
Control Plane API Server etcd Scheduler Controller Worker Nodes Node 1 kubelet | proxy Node 2 kubelet | proxy kubectl Network Communication

Architecture Components Explained

Control Plane (Master)

The brain of Kubernetes - makes global decisions about the cluster and responds to cluster events.

Worker Nodes

The machines (VMs or physical) that run your containerized applications.

Pods

The smallest deployable units that contain one or more containers.

Control Plane Components

Component Purpose Key Functions
kube-apiserver API endpoint for Kubernetes Validates and processes REST requests, updates etcd, only component that talks to etcd
etcd Distributed key-value store Stores all cluster data, provides high availability, source of truth for cluster state
kube-scheduler Assigns pods to nodes Watches for new pods, selects best node, considers resource requirements
kube-controller-manager Runs controller processes Node controller, Replication controller, Endpoints controller
cloud-controller-manager Cloud-specific control logic Node controller, Route controller, Service controller

Node Components

Key Node Components

  • kubelet: Agent that runs on each node, ensures containers are running in pods
  • kube-proxy: Network proxy that maintains network rules for pod communication
  • Container Runtime: Software for running containers (Docker, containerd, CRI-O)
check-components.sh
# View all components in kube-system namespace
kubectl get pods -n kube-system

# Check component status
kubectl get componentstatuses

# View nodes in cluster
kubectl get nodes -o wide

# Describe a specific node
kubectl describe node <node-name>

Hands-On: Exploring Your Cluster

Let's Explore a Real Cluster!

Follow these steps to understand your Kubernetes cluster structure.

Step 1: Basic Cluster Information

cluster-info.sh
# Get cluster information
kubectl cluster-info

# View kubectl configuration
kubectl config view

# Get current context
kubectl config current-context

# List all contexts
kubectl config get-contexts

Step 2: Create Your First Namespace

namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: my-first-namespace
  labels:
    environment: learning
    created-by: tutorial
apply-and-verify.sh
# Create the namespace
kubectl apply -f namespace.yaml

# List all namespaces
kubectl get namespaces

# Describe the namespace
kubectl describe namespace my-first-namespace

Step 3: Understanding API Resources

explore-api.sh
# List all available API resources
kubectl api-resources

# Get API versions
kubectl api-versions

# Explain a resource
kubectl explain pods
kubectl explain pods.spec.containers

Common Pitfall

Problem: "The connection to the server localhost:8080 was refused"

Solution: This means kubectl can't connect to your cluster. Check:

  • Is your cluster running? (minikube status, kind get clusters)
  • Is KUBECONFIG environment variable set correctly?
  • Run: kubectl config view to check configuration

Practice Exercises

Easy Cluster Exploration

Familiarize yourself with cluster components:

  1. List all nodes in your cluster
  2. Check which pods are running in kube-system namespace
  3. Find out which version of Kubernetes you're running
  4. Identify the container runtime on your nodes

Use kubectl get with different resource types and flags like -n for namespace and -o wide for extra details.

# 1. List nodes
kubectl get nodes

# 2. Pods in kube-system
kubectl get pods -n kube-system

# 3. Kubernetes version
kubectl version --short

# 4. Container runtime
kubectl get nodes -o wide

Easy Working with Namespaces

Create and manage namespaces:

  1. Create a namespace called "development"
  2. Create another namespace called "production"
  3. Add labels to identify environments
  4. Set resource quotas for the development namespace

Use kubectl create namespace for imperative creation, and kubectl label to add labels. For resource quotas, use a YAML manifest with kind: ResourceQuota.

# Create namespaces
kubectl create namespace development
kubectl create namespace production

# Add labels
kubectl label namespace development env=dev
kubectl label namespace production env=prod

# Create resource quota
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ResourceQuota
metadata:
  name: dev-quota
  namespace: development
spec:
  hard:
    requests.cpu: "1"
    requests.memory: 1Gi
    limits.cpu: "2"
    limits.memory: 2Gi
EOF

Medium API Server Interaction

Understand how kubectl communicates with the API server:

  1. Use kubectl with increased verbosity to see API calls
  2. Get raw JSON output for a namespace
  3. Use kubectl proxy to access the API directly

The -v flag controls verbosity level (1-10). Use -o json for raw output. kubectl proxy sets up a local proxy to the API server.

# 1. Verbose output
kubectl get nodes -v=8

# 2. Raw JSON
kubectl get namespace default -o json

# 3. Start proxy
kubectl proxy --port=8001 &
# Access API
curl http://localhost:8001/api/v1/namespaces

Pro Tip

Start with the basic cluster exploration exercises and work your way up. Understanding the architecture first will make everything else in Kubernetes click!

Quick Reference

Essential kubectl Commands

Command Description Example
kubectl get List resources kubectl get nodes
kubectl describe Show detailed information kubectl describe node node-1
kubectl create Create a resource kubectl create namespace test
kubectl apply Apply configuration kubectl apply -f config.yaml
kubectl delete Delete resources kubectl delete namespace test
kubectl logs View container logs kubectl logs pod-name
kubectl exec Execute command in container kubectl exec -it pod-name -- bash

Kubernetes Object Model

Key Concepts

  • API Version: The version of the Kubernetes API you're using (e.g., v1, apps/v1)
  • Kind: The type of object you want to create (e.g., Pod, Service, Deployment)
  • Metadata: Data that helps uniquely identify the object (name, labels, namespace)
  • Spec: The desired state of the object
  • Status: The current state of the object (managed by Kubernetes)

Useful Resources