Docker and Kubernetes are complementary, not competitors. Docker packages and runs containers; Kubernetes orchestrates many containers across many machines. Docker - A platform for building, shipping and running containers. - A container packages an application with its dependencies (runtime, libraries, configuration) into an image that runs the same way everywhere. - Main pieces: Dockerfile (build instructions), images, containers, Docker Engine, registries (Docker Hub, Azure Container Registry, Amazon ECR), and Docker Compose for running multi-container setups on one machine. docker build -t orders-api:1.0 . docker run -d -p 8080:8080 orders-api:1.0 Kubernetes (K8s) - An open-source container orchestration platform originally developed by Google, now maintained by the CNCF. - Runs containers across a cluster of nodes and manages them automatically: - Scheduling containers onto nodes with enough resources. - Self-healing: restarting failed containers and replacing unhealthy pods. - Scaling: Horizontal Pod Autoscaler adds or removes replicas based on load. - Service discovery and load balancing between replicas. - Rolling updates and rollbacks with zero downtime. - Configuration and secrets management (ConfigMaps, Secrets). - Storage orchestration (persistent volumes). - Core objects: Pods, Deployments, Services, Ingress, ConfigMaps, Secrets, Namespaces. apiVersion: apps/v1 kind: Deployment metadata: { name: orders-api } spec: replicas: 3 selector: { matchLabels: { app: orders-api } } template: metadata: { labels: { app: orders-api } } spec: containers: - name: orders-api image: myregistry.azurecr.io/orders-api:1.0 ports: [{ containerPort: 8080 }] Key differences - Purpose: Docker creates and runs containers; Kubernetes manages containers at scale across machines. - Scope: Docker typically works on a single host; Kubernetes manages a cluster. - Scaling and healing: Docker alone does not automatically reschedule containers to other machines; Kubernetes does. - Complexity: Docker is simple to start with; Kubernetes has a steeper learning curve and more operational overhead. How they work together 1. Developers write a Dockerfile and build an image (with Docker or another builder such as Buildah). 2. The image is pushed to a registry. 3. Kubernetes pulls the image and runs it as pods on cluster nodes. Note: Kubernetes no longer uses Docker Engine directly as its runtime (dockershim was removed in Kubernetes 1.24); it uses containerd or CRI-O. Images built with Docker still work because they follow the OCI standard. When you need Kubernetes - Many services, high availability requirements, autoscaling, and teams able to operate it — often through managed services (AKS, EKS, GKE). For simpler needs, platforms like Azure Container Apps, AWS App Runner or Google Cloud Run run containers without managing Kubernetes yourself. Interview summary: "Docker builds and runs containers; Kubernetes orchestrates containers across a cluster, handling scheduling, scaling, self-healing and deployments."
Ravindra Wadile · · 0 likes