Kubernetes (K8s) is an open-source container orchestration platform that automates deployment, scaling, and management of containerized applications across clusters of hosts. Originally designed by Google and now maintained by the Cloud Native Computing Foundation (CNCF), it provides a framework to run distributed systems resiliently.
Core Concepts
- Pods: The smallest deployable units in Kubernetes, containing one or more containers that share storage, network, and specifications.
- Nodes: Worker machines in Kubernetes that run containers; each node is managed by the control plane.
- Cluster: A set of nodes that run containerized applications managed by Kubernetes.
- Control Plane: The container orchestration layer that manages the worker nodes and pods.
- Services: Abstractions that define logical sets of pods and policies for accessing them.
- Deployments: Objects that define how applications should be deployed and updated.
- Namespaces: Virtual clusters that provide isolation of resources within a physical cluster.
Key Features
- Service Discovery and Load Balancing: Kubernetes can expose a container using the DNS name or using their own IP address.
- Storage Orchestration: Automatically mount storage systems of your choice, whether from local storage, public cloud providers, or network storage.
- Automated Rollouts and Rollbacks: Kubernetes progressively rolls out changes to your application while monitoring application health.
- Secret and Configuration Management: Deploy and update secrets and application configuration without rebuilding images.
- Self-Healing: Restarts failed containers, replaces containers, kills containers that don't respond to user-defined health checks.
- Horizontal Scaling: Scale applications up and down with a single command, with auto-scaling based on CPU usage.
Architecture
- etcd: Consistent and highly-available key-value store used as Kubernetes' backing store for all cluster data.
- API Server: Exposes the Kubernetes API and is the front end for the Kubernetes control plane.
- Controller Manager: Runs controller processes that regulate the state of the cluster.
- Scheduler: Watches for newly created pods with no assigned node and selects a node for them to run on.
- Kubelet: An agent that runs on each node and ensures containers are running in a pod.
- Kube-proxy: Maintains network rules on nodes to allow network communication to pods.
Common Commands
kubectl get: Lists resourceskubectl describe: Shows detailed information about a resourcekubectl create: Creates resources from files or stdinkubectl apply: Applies a configuration change to a resourcekubectl delete: Deletes resourceskubectl logs: Prints pod/container logskubectl exec: Executes a command in a container
Use Cases
- Microservices orchestration
- Auto-scaling applications
- Multi-cloud deployments
- DevOps and CI/CD pipelines
- Stateful applications
- Batch processing workloads