Kubernetes Fundamentals - Complete Interview Guide

Learn Kubernetes fundamentals including architecture, Pods, ReplicaSets, Deployments, Services, ConfigMaps, Secrets, Storage, Networking, Ingress, kubectl, scaling, and production best practices.

Introduction

Kubernetes (K8s) is an open-source container orchestration platform developed by Google and maintained by the Cloud Native Computing Foundation (CNCF).

It automates container deployment, scaling, networking, storage, self-healing, and application lifecycle management.

Today, Kubernetes is the industry standard for running containerized applications in production.


Learning Objectives

After completing this chapter, you should understand:

  • What is Kubernetes?
  • Why Kubernetes?
  • Container Orchestration
  • Kubernetes Architecture
  • Control Plane
  • Worker Nodes
  • Pods
  • ReplicaSets
  • Deployments
  • Services
  • Namespaces
  • Labels & Selectors
  • ConfigMaps
  • Secrets
  • Volumes
  • Persistent Volumes
  • Persistent Volume Claims
  • Storage Classes
  • Ingress
  • kubectl
  • Scaling
  • Rolling Updates
  • Rollbacks
  • Self-Healing
  • Best Practices

What is Kubernetes?

Kubernetes is a container orchestration platform that manages the complete lifecycle of containers.

It automatically:

  • Deploys containers
  • Scales applications
  • Restarts failed containers
  • Performs rolling updates
  • Load balances traffic
  • Manages networking
  • Manages storage

Why Kubernetes?

Without Kubernetes:

  • Manual deployments
  • Difficult scaling
  • No automatic recovery
  • Manual load balancing
  • Hard to manage multiple containers

With Kubernetes:

  • Automated deployment
  • Auto scaling
  • Self healing
  • High availability
  • Service discovery
  • Load balancing
  • Rolling updates

What is Container Orchestration?

Container orchestration automates the deployment and management of containers.

Responsibilities include:

  • Scheduling
  • Scaling
  • Networking
  • Storage
  • Monitoring
  • Recovery

Kubernetes Architecture

                 Kubernetes Cluster
---------------------------------------------------

             Control Plane

+--------------------------------------------+
| API Server                                 |
| Scheduler                                  |
| Controller Manager                         |
| etcd                                       |
+--------------------------------------------+

                    │

        ----------------------------

          Worker Node 1

+-------------------------------+
| kubelet                       |
| kube-proxy                    |
| Container Runtime             |
| Pods                          |
+-------------------------------+

          Worker Node 2

+-------------------------------+
| kubelet                       |
| kube-proxy                    |
| Container Runtime             |
| Pods                          |
+-------------------------------+

Kubernetes Cluster

A Kubernetes Cluster consists of:

  • Control Plane
  • Worker Nodes

The Control Plane manages the cluster.

Worker Nodes run application workloads.


Control Plane Components

Main components:

  • API Server
  • Scheduler
  • Controller Manager
  • etcd

API Server

The API Server is the entry point of Kubernetes.

Responsibilities:

  • Accept API requests
  • Validate requests
  • Authentication
  • Authorization
  • Update cluster state

etcd

etcd is a distributed key-value database.

Stores:

  • Cluster state
  • Configuration
  • Secrets
  • Node information

Scheduler

The Scheduler decides which Worker Node should run a Pod.

Scheduling considers:

  • Available CPU
  • Memory
  • Resource requests
  • Node affinity
  • Taints
  • Tolerations

Controller Manager

Controllers continuously monitor cluster state.

Examples:

  • Deployment Controller
  • ReplicaSet Controller
  • Node Controller
  • Job Controller

Worker Node

A Worker Node executes application workloads.

Components:

  • kubelet
  • kube-proxy
  • Container Runtime
  • Pods

kubelet

kubelet communicates with the Control Plane.

Responsibilities:

  • Start Pods
  • Stop Pods
  • Monitor Pods
  • Report Node Status

kube-proxy

kube-proxy manages networking.

Responsibilities:

  • Service routing
  • Load balancing
  • Network rules

Container Runtime

Container Runtime executes containers.

Examples:

  • containerd
  • CRI-O

Pod

A Pod is the smallest deployable unit in Kubernetes.

A Pod contains:

  • One or more containers
  • Shared network
  • Shared storage

Pod Architecture

Pod

+----------------------+

Container A

Container B

Shared Network

Shared Volume

+----------------------+

ReplicaSet

ReplicaSet ensures the desired number of Pods are always running.

Example:

Desired Pods = 3

If one Pod crashes,

ReplicaSet creates another Pod automatically.


Deployment

Deployment manages ReplicaSets and Pods.

Features:

  • Rolling updates
  • Rollbacks
  • Scaling
  • Version management

Deployment Architecture

Deployment

      │

ReplicaSet

      │

Pods

Labels

Labels are key-value pairs attached to Kubernetes resources.

Example

app=payment

environment=production

Selectors

Selectors identify resources using labels.

Example

app=payment

Namespaces

Namespaces logically separate resources.

Common namespaces:

  • default
  • kube-system
  • kube-public
  • development
  • production

Kubernetes Services

Services expose Pods.

Types:

  • ClusterIP
  • NodePort
  • LoadBalancer
  • ExternalName

ClusterIP

Default service type.

Accessible only inside the cluster.


NodePort

Exposes applications through a Node's IP and port.

Useful for testing.


LoadBalancer

Creates an external load balancer.

Common in cloud environments.


ExternalName

Maps a Service to an external DNS name.


Service Architecture

Client

    │

Service

    │

Pods

Pod A

Pod B

Pod C

ConfigMap

ConfigMaps store application configuration.

Examples:

  • URLs
  • Feature flags
  • Logging configuration
  • Application properties

Secret

Secrets securely store sensitive information.

Examples:

  • Passwords
  • API Keys
  • Tokens
  • Certificates

Volumes

Volumes provide storage shared between containers.

Benefits:

  • Data persistence
  • Shared storage
  • Backup

Persistent Volume (PV)

Persistent Volume is cluster storage provisioned by administrators.

Examples:

  • AWS EBS
  • Azure Disk
  • NFS
  • Local Storage

Persistent Volume Claim (PVC)

PVC requests storage from Kubernetes.

Applications consume PVC instead of directly using storage.


Storage Class

StorageClass enables dynamic storage provisioning.

Benefits:

  • Automatic volume creation
  • Cloud integration
  • Better storage management

Ingress

Ingress exposes HTTP and HTTPS applications.

Features:

  • URL Routing
  • SSL Termination
  • Load Balancing
  • Virtual Hosts

Ingress Architecture

Internet

      │

Ingress

      │

Service

      │

Pods

kubectl

kubectl is the Kubernetes command-line tool.

Common commands:

kubectl get pods

kubectl get nodes

kubectl describe pod

kubectl logs

kubectl exec

kubectl apply

kubectl delete

Scaling

Applications can be scaled manually.

Example:

kubectl scale deployment payment --replicas=5

Rolling Updates

Rolling Updates replace old Pods gradually.

Benefits:

  • Zero downtime
  • Safer deployments
  • Easy rollback

Rollback

Rollback restores a previous Deployment version.

Useful after failed releases.


Self-Healing

Kubernetes automatically:

  • Restarts failed containers
  • Recreates deleted Pods
  • Replaces unhealthy Pods
  • Reschedules Pods

Kubernetes Workflow

Developer

      │

Docker Image

      │

Deployment YAML

      │

API Server

      │

Scheduler

      │

Worker Node

      │

Pod

      │

Service

      │

Users

Common kubectl Commands

Command Purpose
kubectl get List resources
kubectl describe Detailed information
kubectl apply Create or update resources
kubectl delete Delete resources
kubectl logs View logs
kubectl exec Execute commands
kubectl scale Scale applications
kubectl rollout Manage deployments
kubectl expose Create services
kubectl config Manage cluster configuration

Enterprise Kubernetes Workflow

Developer

      │

Git

      │

CI Pipeline

      │

Docker Image

      │

Container Registry

      │

Kubernetes Deployment

      │

Pods

      │

Services

      │

Ingress

      │

Users

Common Use Cases

Kubernetes is commonly used for:

  • Spring Boot Applications
  • Java Microservices
  • REST APIs
  • Cloud Applications
  • AI Workloads
  • Batch Processing
  • Event-Driven Applications
  • CI/CD Pipelines

Best Practices

  • Use Deployments instead of standalone Pods.
  • Define CPU and Memory requests.
  • Configure resource limits.
  • Store configuration in ConfigMaps.
  • Store sensitive data in Secrets.
  • Use Readiness and Liveness Probes.
  • Keep Pods stateless whenever possible.
  • Use Namespaces for environment isolation.
  • Apply labels consistently.
  • Use Ingress instead of exposing multiple NodePorts.
  • Monitor cluster health regularly.

Interview Summary

After completing this chapter, you should understand:

  • Kubernetes
  • Container Orchestration
  • Kubernetes Cluster
  • Control Plane
  • Worker Nodes
  • API Server
  • Scheduler
  • Controller Manager
  • etcd
  • kubelet
  • kube-proxy
  • Pods
  • ReplicaSets
  • Deployments
  • Services
  • Labels
  • Selectors
  • Namespaces
  • ConfigMaps
  • Secrets
  • Volumes
  • Persistent Volumes
  • Persistent Volume Claims
  • Storage Classes
  • Ingress
  • kubectl
  • Scaling
  • Rolling Updates
  • Rollbacks
  • Self-Healing

Next Chapter

➡️ Kubernetes Advanced

Topics include:

  • Kubernetes Internals
  • Scheduling Process
  • StatefulSets
  • DaemonSets
  • Jobs
  • CronJobs
  • Horizontal Pod Autoscaler (HPA)
  • Vertical Pod Autoscaler (VPA)
  • Cluster Autoscaler
  • Network Policies
  • RBAC
  • Helm
  • Operators
  • CSI
  • CNI
  • Service Mesh
  • Observability
  • GitOps
  • Production Best Practices