Beginner

Kubernetes Basic Concepts and Configuration

Cluster architecture, pods, services, deployments, core objects and basic kubectl administration.

Table of Contents

  1. Introduction to Kubernetes
  2. Kubernetes Cluster Architecture
  3. Pods and the Service Abstraction
  4. Deployments and Manifests
  5. Fundamental Kubernetes Objects
  6. Installing and Configuring Kubernetes
  7. Cluster Initialization
  8. Deploying a Kubernetes Service
  9. Basic Administration with kubectl
  10. kubectl Reference
  11. Complete YAML Examples

1. Introduction to Kubernetes

Kubernetes (also written K8s, where the number 8 represents the 8 letters between K and S) is an open-source container orchestration platform created by Google and now maintained by the Cloud Native Computing Foundation (CNCF).

Why Kubernetes?

Companies like Google, Netflix, Spotify, and Amazon use Kubernetes to deploy and operate thousands of services at scale. Kubernetes provides:

  • Automation of container deployment, scaling, and management
  • High availability through pod replication
  • Self-healing: automatic restart on failure
  • Dynamic horizontal scalability
  • Portability: on-premise, public cloud, hybrid

Hosting Options

TypeDescriptionExamples
Self-managedYou deploy and manage every node yourselfkubeadm on VMs
Managed clusterCloud provider manages the control planeEKS (AWS), AKS (Azure), GKE (GCP)
Local / DevFor local developmentminikube, kind, k3s

2. Kubernetes Cluster Architecture

A Kubernetes cluster consists of two types of nodes: master nodes (control plane) and worker nodes.

Cluster Architecture Diagram

graph TB
    subgraph "Control Plane (Master Nodes)"
        API["API Server\n(kube-apiserver)"]
        SCHED["Scheduler\n(kube-scheduler)"]
        CM["Controller Manager\n(kube-controller-manager)"]
        ETCD["etcd\n(cluster state store)"]
        API --> ETCD
        API --> SCHED
        API --> CM
    end

    subgraph "Worker Node 1"
        KP1["kubelet"]
        KPX1["kube-proxy"]
        POD1["Pod: nginx-1"]
        POD2["Pod: nginx-2"]
        KP1 --> POD1
        KP1 --> POD2
    end

    subgraph "Worker Node 2"
        KP2["kubelet"]
        KPX2["kube-proxy"]
        POD3["Pod: nginx-3"]
        KP2 --> POD3
    end

    API -->|"schedule pods"| KP1
    API -->|"schedule pods"| KP2
    KUBECTL["kubectl (admin)"] -->|"kubectl apply / get / describe"| API

Control Plane Components

ComponentRole
kube-apiserverSingle entry point for all cluster communication. Exposes the Kubernetes REST API.
etcdDistributed key-value database storing the complete cluster state.
kube-schedulerAssigns new pods to worker nodes based on available resources and constraints.
kube-controller-managerRuns controllers (ReplicaSet, Node, etc.) that maintain desired state.

Worker Node Components

ComponentRole
kubeletAgent on each worker node, receives control plane instructions and manages pods.
kube-proxyManages network rules to enable communication to pods.
Container RuntimeContainer execution engine (containerd, CRI-O).

Why an Odd Number of Master Nodes?

In production, use 3, 5, or 7 master nodes. Must be an odd number to avoid split-brain: with 4 masters, two could vote one way and two the other, with no majority. With 5 masters, 3 can always outvote 2, guaranteeing consensus.


3. Pods and the Service Abstraction

Pods

A Pod is the basic unit of deployment in Kubernetes. A pod is a group of one or more containers that share:

  • The same network space (they communicate via localhost)
  • The same storage (shared volumes)
  • The same lifecycle

Pods are deployed only on worker nodes. The Scheduler automatically decides which worker node to place each pod on based on available resources (CPU, RAM, storage).

Services

A Service is a stable abstraction that exposes one or more pods under a unique IP address and DNS name. It enables:

  • Providing a stable endpoint even when pods restart (their IPs change)
  • Load balancing between multiple identical pods
  • Exposing applications inside or outside the cluster

The Service is the “façade”: clients never talk directly to pods, they always go through the Service.

Service Types

TypeDescriptionUsage
ClusterIPAccessible only inside the clusterInter-service communication
NodePortExposes a fixed port on each nodeSimple external access (dev)
LoadBalancerCreates a cloud load balancerProduction on cloud
ExternalNameMaps to an external DNS nameAccess to external services

4. Deployments and Manifests

What Is a Deployment?

A Deployment controls the complete lifecycle of an application in the cluster. It’s declarative management: you describe the desired state in a YAML file (the manifest), and Kubernetes ensures reality matches that description.

Deployment Flow Diagram

flowchart LR
    DEV["Developer\n(YAML file)"]
    KUBECTL["kubectl apply -f"]
    API["API Server"]
    ETCD["etcd\n(desired state)"]
    CM["Controller Manager\n(ReplicaSet Controller)"]
    SCHED["Scheduler"]
    NODE1["Worker Node 1\nkubelet → Pod A"]
    NODE2["Worker Node 2\nkubelet → Pod B, C"]

    DEV -->|"YAML manifest"| KUBECTL
    KUBECTL -->|"HTTP POST"| API
    API -->|"persists"| ETCD
    ETCD -->|"notifies"| CM
    CM -->|"creates ReplicaSet"| SCHED
    SCHED -->|"assigns pods"| NODE1
    SCHED -->|"assigns pods"| NODE2

Key Deployment Features

FeatureDescription
Desired State ConfigurationYAML describes the target state (replica count, image, ports…)
ReplicaSet ManagementMaintains defined number of identical pods (e.g., 3 Nginx replicas)
Automated RolloutsZero-downtime updates: pods are progressively replaced
Automated RollbacksAutomatic rollback to previous version on error
ScalingManual (kubectl scale) or automatic via HPA
Self-HealingContinuously compares desired vs actual state, auto-corrects

5. Fundamental Kubernetes Objects

Object Relationships Diagram

graph TD
    NS["Namespace\n(logical isolation)"]
    DEP["Deployment\n(lifecycle)"]
    RS["ReplicaSet\n(replica count)"]
    POD["Pod\n(containers)"]
    SVC["Service\n(stable endpoint)"]
    CM2["ConfigMap\n(configuration)"]
    SEC["Secret\n(sensitive data)"]
    PV["PersistentVolume\n(storage)"]

    NS --> DEP
    NS --> SVC
    NS --> CM2
    DEP --> RS
    RS --> POD
    SVC -->|"selects via labels"| POD
    CM2 -->|"injects config"| POD
    SEC -->|"injects secrets"| POD
    PV -->|"mounts volume"| POD

Main Object Descriptions

ObjectapiVersionDescription
Podv1Basic unit, groups 1+ containers sharing network and storage
Deploymentapps/v1Manages lifecycle and replica count of an application
ReplicaSetapps/v1Maintains desired number of identical pods (managed by Deployment)
Servicev1Exposes pods via a stable endpoint with load balancing
ConfigMapv1Stores non-sensitive configuration (env vars, config files)
Secretv1Stores sensitive base64-encoded data (passwords, tokens)
Namespacev1Logically isolates resources in the cluster
PersistentVolumev1Persistent storage resource in the cluster

Default Namespaces

NamespaceContents
defaultResources deployed without a specified namespace
kube-systemKubernetes system components (API server, scheduler, DNS…)
kube-publicPublic data (e.g., bootstrap config)
kube-node-leaseNode heartbeats

6. Installing and Configuring Kubernetes

Hardware Prerequisites (Production)

ResourceMinimumRecommended
CPU2 vCPUs4+ vCPUs
RAM4 GB8 GB
Storage40 GB100+ GB
OSUbuntu 22.04/24.04Ubuntu 24.04 LTS

Minimum Architecture for a Dev Cluster

  • 1 master node (or 3 in production)
  • 2 worker nodes minimum
  • All nodes must be in the same network zone (same VPC/subnet)

Required Network Ports

PortProtocolUsage
22TCPSSH for node administration
443TCPHTTPS (Kubernetes API)
6443TCPkube-apiserver (kubectl access)
2379-2380TCPetcd (internal communication)
10250TCPkubelet API
30000-32767TCPNodePort Services

Installation Steps with kubeadm (Ubuntu 24.04)

On all nodes (master + workers)

# 1. Disable swap (required for Kubernetes)
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

# 2. Enable required kernel modules
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter

# 3. Sysctl parameters for networking
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF
sudo sysctl --system

# 4. Install containerd (container runtime)
sudo apt-get update
sudo apt-get install -y containerd

# 5. Install kubeadm, kubelet, kubectl
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | \
  sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] \
  https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | \
  sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

7. Cluster Initialization

On the Master Node Only

# Initialize the cluster with network CIDR for Calico
sudo kubeadm init --pod-network-cidr=192.168.0.0/16

Configure kubectl After Initialization

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

Install Network Plugin (Calico)

kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/calico.yaml

Join Worker Nodes

After master initialization, a join command is displayed. Run it on each worker:

# Example command generated by kubeadm init
sudo kubeadm join <MASTER_IP>:6443 --token <token> \
    --discovery-token-ca-cert-hash sha256:<hash>

If you missed the join command, regenerate it with:

kubeadm token create --print-join-command

Verify Cluster State

kubectl get nodes

# Expected output:
# NAME         STATUS   ROLES           AGE   VERSION
# ps2-k8s-m    Ready    control-plane   5m    v1.30.0
# ps2-k8s-w1   Ready    <none>          3m    v1.30.0
# ps2-k8s-w2   Ready    <none>          3m    v1.30.0

8. Deploying a Kubernetes Service

Deploy an Nginx Application via kubectl

# Quick Nginx deployment creation
kubectl create deployment nginx --image=nginx --replicas=3

# Expose the deployment via a NodePort Service
kubectl expose deployment nginx --port=80 --type=NodePort

# Verify deployment
kubectl get deployments
kubectl get pods
kubectl get services

9. Basic Administration with kubectl

kubectl Command Flow

flowchart LR
    USER["Administrator"] -->|"kubectl <verb> <resource>"| KUBECTL["kubectl CLI"]
    KUBECTL -->|"HTTP/HTTPS :6443"| API["kube-apiserver"]
    API -->|"queries / modifies"| ETCD["etcd"]
    API -->|"responds"| KUBECTL
    KUBECTL -->|"displays"| USER

General Syntax

kubectl [verb] [resource] [name] [flags]

Main verbs: get, describe, apply, create, delete, logs, exec, scale, rollout, port-forward

Main resources: pods, deployments, services, configmaps, namespaces, nodes, replicasets


10. kubectl Reference

Essential Commands

CommandDescription
kubectl get nodesList all cluster nodes with their status
kubectl get podsList pods in default namespace
kubectl get pods -n kube-systemList pods in kube-system namespace
kubectl get pods -o wideList pods with more information (IP, node)
kubectl get allList all resources in current namespace
kubectl get deploymentsList all deployments
kubectl get servicesList all services

Inspection and Debugging

CommandDescription
kubectl describe pod <name>Full pod details (events, config)
kubectl describe deployment <name>Deployment details and events
kubectl logs <pod>Display pod logs
kubectl logs <pod> -fFollow logs in real time
kubectl logs <pod> -c <container>Logs for a specific container in a multi-container pod
kubectl exec -it <pod> -- bashInteractive shell inside a pod
kubectl get eventsDisplay recent cluster events

Deployment and Management

CommandDescription
kubectl apply -f <file.yaml>Apply a YAML manifest (create or update)
kubectl delete -f <file.yaml>Delete resources defined in a manifest
kubectl delete pod <name>Delete a pod (will be recreated by ReplicaSet)
kubectl scale deployment <name> --replicas=5Change replica count
kubectl rollout status deployment/<name>Check rollout status
kubectl rollout history deployment/<name>Deployment revision history
kubectl rollout undo deployment/<name>Roll back to previous version

Namespaces and Contexts

CommandDescription
kubectl get namespacesList all namespaces
kubectl get pods -n <namespace>Pods in a specific namespace
kubectl config get-contextsList available kubeconfig contexts
kubectl config use-context <name>Change active context (switch cluster)
kubectl config current-contextDisplay active context

Useful Flags

FlagDescription
-n <namespace>Specify namespace
-o wideExtended display
-o yamlYAML format output
-o jsonJSON format output
--all-namespaces or -AAll namespaces
-l <label>=<value>Filter by label selector
--dry-run=clientSimulate without applying

11. Complete YAML Examples

Simple Pod

# pod-nginx.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  namespace: default
  labels:
    app: nginx
    tier: frontend
spec:
  containers:
    - name: nginx
      image: nginx:1.25
      ports:
        - containerPort: 80
      resources:
        requests:
          memory: "64Mi"
          cpu: "250m"
        limits:
          memory: "128Mi"
          cpu: "500m"

Namespace

# namespace-dev.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: development
  labels:
    environment: dev

ConfigMap

# configmap-app.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  namespace: default
data:
  APP_ENV: "production"
  APP_PORT: "8080"
  LOG_LEVEL: "info"
  app.properties: |
    database.host=postgres-service
    database.port=5432
    cache.ttl=300

Complete Deployment

# deployment-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: default
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.25
          ports:
            - containerPort: 80
          env:
            - name: APP_ENV
              valueFrom:
                configMapKeyRef:
                  name: app-config
                  key: APP_ENV
          resources:
            requests:
              memory: "64Mi"
              cpu: "250m"
            limits:
              memory: "128Mi"
              cpu: "500m"
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 10
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 5
            periodSeconds: 5

NodePort Service

# service-nginx.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: default
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30080        # Exposed on each worker node (30000-32767)

Secret

# secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: db-credentials
  namespace: default
type: Opaque
data:
  # Values encoded in base64: echo -n "mypassword" | base64
  username: YWRtaW4=
  password: bXlwYXNzd29yZA==

Key Terms Glossary

TermDefinition
kubeadmCLI tool for initializing and managing a Kubernetes cluster
kubectlMain CLI tool for interacting with the Kubernetes API
kubeconfigConfiguration file for kubectl cluster access
etcdDistributed database storing cluster state
CIDRIP address range for the cluster’s internal network
ManifestYAML file describing the desired state of a Kubernetes object
Desired StateTarget configuration defined in YAML
Actual StateCurrently running state in the cluster
Rolling UpdateProgressive update without service interruption
RollbackReturn to a previous version of a deployment
LensGUI for visually managing K8s clusters
CalicoPopular network plugin (CNI) for Kubernetes
HPAHorizontal Pod Autoscaler — automatic scaling
Split BrainConsensus problem with an even number of masters
K8s / K8SAbbreviation for Kubernetes (8 letters between K and S)

Search Terms

kubernetes · concepts · configuration · containers · cluster · deployment · kubectl · service · architecture · diagram · master · nodes · components · flow · initialization · namespaces · network · node · object · pods · worker

Interested in this course?

Contact us to book it or get a custom training plan for your team.