DevOps

Kubernetes Basics

Learn Kubernetes fundamentals: architecture, pods, nodes, clusters, and the control plane. Understand how container orchestration works.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Learn Kubernetes fundamentals: architecture, pods, nodes, clusters, and the control plane. Understand how container orchestration works. This hands-on tutorial focuses on practical implementation of kubernetes basics concepts.

Kubernetes Basics

Kubernetes (K8s) is the industry-standard platform for automating deployment, scaling, and management of containerized applications.

What is Kubernetes?

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services.

┌───────────────────────────────────────────────────────────────────┐
│                      Kubernetes Cluster                            │
├───────────────────────────────────────────────────────────────────┤
│                                                                    │
│   ┌──────────────────────────────────────────────────────────┐   │
│   │                   Control Plane                           │   │
│   │  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐  │   │
│   │  │ API      │  │ etcd     │  │ Scheduler│  │ Controller│  │   │
│   │  │ Server   │  │          │  │          │  │ Manager   │  │   │
│   │  │ (kube-apiserver)│       │  │          │  │           │  │   │
│   │  └──────────┘  └──────────┘  └──────────┘  └──────────┘  │   │
│   └──────────────────────────────────────────────────────────┘   │
│                           │                                        │
│                           │ manages                                │
│                           ▼                                        │
│   ┌──────────────────────────────────────────────────────────┐   │
│   │                     Worker Nodes                        │   │
│   │  ┌──────────────┐    ┌──────────────┐    ┌──────────┐  │   │
│   │  │  Node 1      │    │  Node 2      │    │  Node 3  │  │   │
│   │  │ ┌──────────┐│    │ ┌──────────┐│    │ ┌──────┐ │  │   │
│   │  │ │ kubelet  ││    │ │ kubelet  ││    ││kubelet│ │  │   │
│   │  │ ├──────────┤│    │ ├──────────┤│    │├──────┤ │  │   │
│   │  │ │ Container││    │ │ Container││    ││Container│ │   │
│   │  │ │ Runtime  ││    │ │ Runtime  ││    ││Runtime│ │  │   │
│   │  │ ├──────────┤│    │ ├──────────┤│    │├──────┤ │  │   │
│   │  │ │ kube-proxy││   │ │ kube-proxy││    ││kube-proxy│ │   │
│   │  │ └──────────┘│    │ └──────────┘│    │└──────┘ │  │   │
│   │  │             │    │             │    │         │  │   │
│   │  │ Pods running│    │ Pods running│    │Pods run │  │   │
│   │  └──────────────┘    └──────────────┘    └──────────┘  │   │
│   └──────────────────────────────────────────────────────────┘   │
│                                                                    │
└───────────────────────────────────────────────────────────────────┘

Kubernetes Architecture

Control Plane Components

ComponentPurpose
kube-apiserverExposes Kubernetes API; front-end for control plane
etcdConsistent and highly-available key-value store for all cluster data
kube-schedulerWatches for new Pods and assigns them to nodes
kube-controller-managerRuns controller processes (Node, Job, Endpoint, etc.)
cloud-controller-managerIntegrates with underlying cloud providers

Node Components

ComponentPurpose
kubeletEnsures containers are running in a Pod
kube-proxyMaintains network rules on nodes
Container RuntimeSoftware responsible for running containers (containerd, CRI-O)

Core Concepts

Pods

The smallest deployable unit in Kubernetes—one or more containers with shared resources.

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
    tier: frontend
spec:
  containers:
  - name: nginx
    image: nginx:alpine
    ports:
    - containerPort: 80
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
    livenessProbe:
      httpGet:
        path: /
        port: 80
      initialDelaySeconds: 30
      periodSeconds: 10
    readinessProbe:
      httpGet:
        path: /ready
        port: 80
      initialDelaySeconds: 5
      periodSeconds: 5

Pod Characteristics:

  • Ephemeral (not designed to persist)
  • Share network namespace (same IP)
  • Share storage volumes
  • Containers in a pod can communicate via localhost

Nodes

Worker machines where pods run.

# View nodes
kubectl get nodes
kubectl get nodes -o wide

# Describe node details
kubectl describe node worker-1

# Check node labels
kubectl get nodes --show-labels

# Cordon node (prevent scheduling)
kubectl cordon worker-1

# Drain node (evict pods)
kubectl drain worker-1 --ignore-daemonsets

# Uncordon node (allow scheduling)
kubectl uncordon worker-1

Namespaces

Virtual clusters within a physical cluster for resource isolation.

# List namespaces
kubectl get namespaces
kubectl get ns

# Create namespace
kubectl create namespace production
kubectl create ns staging

# Set default namespace
kubectl config set-context --current --namespace=production

# Run command in specific namespace
kubectl get pods -n staging
kubectl get pods --namespace=production

kubectl Commands

Essential Commands

# Cluster info
kubectl cluster-info
kubectl version
kubectl api-resources
kubectl api-versions

# Context management
kubectl config get-contexts
kubectl config current-context
kubectl config use-context production

# Resource operations
kubectl get pods
kubectl get pods -o wide
kubectl get pods --all-namespaces
kubectl get pods -l app=nginx
kubectl get pods -o yaml

kubectl describe pod nginx-pod
kubectl logs nginx-pod
kubectl logs nginx-pod -f
kubectl logs nginx-pod --previous

# Execute in container
kubectl exec nginx-pod -- ls /etc/nginx
kubectl exec -it nginx-pod -- /bin/bash

# Port forwarding
kubectl port-forward nginx-pod 8080:80

# Copy files
kubectl cp nginx-pod:/etc/nginx/nginx.conf ./nginx.conf
kubectl cp ./config.conf nginx-pod:/etc/nginx/

# Delete resources
kubectl delete pod nginx-pod
kubectl delete -f manifest.yaml
kubectl delete pods -l app=nginx

Resource Shortcuts

ResourceShortname
podspo
servicessvc
deploymentsdeploy
namespacesns
nodesno
configmapscm
secrets-
persistentvolumeclaimspvc
persistentvolumespv
replicasetsrs
statefulsetssts
daemonsetsds
jobs-
cronjobscj
ingressesing

Installation and Setup

Local Development (minikube/kind)

# Install minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

# Start cluster
minikube start --driver=docker
minikube start --cpus=4 --memory=8192

# Or use kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

kind create cluster --name dev

# Verify
kubectl get nodes

Production (kubeadm)

# On all nodes
sudo apt-get update
sudo apt-get install -y containerd kubelet kubeadm kubectl

# On control plane node
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

# Configure kubectl
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

# Install CNI (Calico)
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

# Join worker nodes
kubeadm join 192.168.1.10:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>

Kubernetes Objects

Imperative vs Declarative

# Imperative (commands)
kubectl run nginx --image=nginx
kubectl create deployment nginx --image=nginx --replicas=3
kubectl expose deployment nginx --port=80 --type=LoadBalancer

# Declarative (manifests)
kubectl apply -f deployment.yaml
kubectl apply -f https://example.com/manifest.yaml
kubectl apply -k ./kustomize/  # Kustomize
kubectl apply -R -f ./manifests/  # Recursive

Resource Manifest Structure

apiVersion: v1       # API version
kind: Pod            # Resource type
metadata:            # Resource metadata
  name: my-pod
  namespace: default
  labels:
    app: myapp
  annotations:
    description: "My application pod"
spec:                # Desired state
  containers:
  - name: app
    image: nginx:alpine

Quiz

Quiz

Question 1 of 5

What is the smallest deployable unit in Kubernetes?

Container
Node
Pod
Deployment

Next Steps

Now let's explore Kubernetes core objects: Deployments, Services, ConfigMaps, and Secrets.