Tags: docker, kubernetes, containers, orchestration, devops, k8s
Level: intermediate
TL;DR: Quick reference for Docker containerization and Kubernetes (K8s) orchestration, covering core concepts, commands, and common interview questions.
Docker is a platform for building, running, and sharing containerized applications.
A container is a lightweight, standalone, executable package including code, runtime, and libraries.
An image is a read-only template with instructions for creating a Docker container.
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containers.
A Pod is the smallest deployable compute unit in K8s, encapsulating one or more containers.
A Node is a worker machine in a K8s cluster (virtual or physical).
A Cluster is a set of Nodes running containerized applications managed by the Control Plane.
A Deployment provides declarative updates for Pods, ensuring the desired state is constantly maintained.
A Service is an abstract way to expose an application running on a set of Pods as a network service.
Q: What is the primary difference between Docker and Kubernetes?
R: Docker is used to create and run individual containers, while Kubernetes is an orchestration tool used to manage, scale, and schedule multiple containers across a cluster of machines.
Q: How do you expose an application to external traffic in Kubernetes?
R: I typically use a Service of type LoadBalancer for direct cloud integration, or an Ingress resource connected to a ClusterIP service to manage HTTP/HTTPS routing rules.
Q: How do you handle persistent data in Docker and Kubernetes?
R: In Docker, I use Volumes or Bind Mounts. In Kubernetes, I configure PersistentVolumes (PV) and request them using PersistentVolumeClaims (PVC) attached to the Pods.
Running containers as the root user, creating significant security vulnerabilities.
Failing to use multi-stage builds, resulting in bloated Docker images with unnecessary build tools.
Omitting resource requests and limits (CPU/Memory) in K8s, leading to node starvation or OOM (Out Of Memory) kills.
Using the latest image tag in K8s manifests, making rollbacks unpredictable and breaking idempotency.
# Docker: Build an image and run it
docker build -t my-app:1.0 .
docker run -d -p 8080:80 --name app-instance my-app:1.0
# Docker: Remove all stopped containers and unused images
docker system prune -a
# K8s: Apply a configuration file
kubectl apply -f deployment.yaml
# K8s: List all pods in all namespaces
kubectl get pods --all-namespaces
# K8s: Get logs for a specific pod
kubectl logs pod-name -c container-name
# K8s: Restart a deployment
kubectl rollout restart deployment/my-deployment
[ ] Kubernetes RBAC (Role-Based Access Control) configuration
[ ] Advanced Ingress controller setups and TLS termination
[ ] Helm chart creation for templating K8s manifests
Docker Official Documentation
Kubernetes Official Documentation
Modifica direttamente o con Gemini Fai clic in un punto qualsiasi per digitare e modificare direttamente oppure seleziona il testo per chiedere a Gemini di apportare modifiche.
The cheat sheet has been generated successfully, strictly following the requested Markdown structure and formatting rules. Let me know if you need any adjustments or if you'd like to create another one!