| title | Kubernetes | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| layout |
|
||||||||||||||||||||||||||
| metaLinks |
|
- Kubernetes is a container orchestration system for managing containerized apps at scale.
- Main objects: Pod, Deployment, ReplicaSet, Service, ConfigMap, Secret, Ingress, PV/PVC, Namespace.
- Control plane components: API Server, Scheduler, Controller Manager, etcd.
- Node components: kubelet, kube-proxy, container runtime (containerd/Docker/CRI-O).
- Smallest deployable unit.
- Usually 1 container per Pod.
- Ephemeral by design — replaced, not repaired.
- Deployment manages ReplicaSets and provides rollout/rollback features.
- Rolling updates by default, supports strategies: RollingUpdate and Recreate.
- Revision history stored in ReplicaSets.
- Stable network endpoint for Pods.
- Types: ClusterIP, NodePort, LoadBalancer, ExternalName.
- Uses kube-proxy (iptables or IPVS) for traffic routing.
- HTTP(S) routing + TLS termination.
- Requires an Ingress Controller (NGINX, Traefik, HAProxy, Cilium, etc.).
- Replaces many NodePort/LoadBalancer services.
- ConfigMaps hold non-sensitive config.
- Secrets hold sensitive data (base64-encoded, optionally encrypted at rest).
- Mounted as env vars or files.
- Every Pod gets a unique IP; Pods can communicate without NAT.
- CNI plugins: Calico, Cilium, Flannel, Weave.
- kube-proxy manages virtual IPs for services.
- Ingress handles L7; Services handle L4.
- PV = cluster-level storage resource.
- PVC = claim requesting storage.
- StorageClass defines dynamic provisioning.
- Common providers: EBS, GCE PD, Ceph, NFS, Longhorn.
- Logical isolation in the cluster.
- Important for RBAC, resource quotas, and multi-tenancy.
- Role/ClusterRole → set of permissions.
- RoleBinding/ClusterRoleBinding → assign permissions.
- Follows the principle of least privilege.
- HPA: scales Pods based on CPU/memory/custom metrics.
- VPA: suggests or sets resource requests/limits.
- Cluster Autoscaler: scales the node pool.
- Liveness: restart container if app is stuck.
- Readiness: remove from Service endpoints until ready.
- Startup: delay other probes until app starts.
requests= minimum guaranteed resources.limits= max allowed resources.- Poor requests/limits → throttling, OOMKills, bad scheduling.
kubectl logs,kubectl exec,kubectl describe,kubectl get events.- Ephemeral containers for debugging in production.
- Metrics with Prometheus + Grafana.
kubectl rollout status,history,undo.- Strategies: rolling, blue/green, canary (via Argo Rollouts/Flagger).
- Disable anonymous access to API server.
- Limit capabilities via PodSecurityContext.
- Use NetworkPolicies for L3/L4 isolation.
- Store secrets in encrypted storage (Vault, KMS).
- Scan images (Trivy, Anchore, Clair).
- Scheduler picks best node based on resources + constraints.
- Affinity/anti-affinity, taints/tolerations influence scheduling.
- NodeSelector = basic placement.
- PriorityClasses control eviction order.
- DaemonSet: runs 1 Pod per node (logging, monitoring).
- Job: run task once until successful.
- CronJob: scheduled Jobs.
- Strongly consistent key-value store.
- Stores all cluster state.
- Backups critical for disaster recovery.
- Explain Pod vs Deployment.
- How does service discovery work?
- Difference between Ingress and Service.
- How HPA works under the hood.
- What’s the purpose of RBAC?
- Pod rescheduling logic when a node dies.
- Taints vs tolerations vs affinity.
- Troubleshooting a CrashLoopBackOff.
- How to secure a cluster.
- StorageClass/PV/PVC workflow.
A Deployment manages stateless apps with interchangeable pods, while a StatefulSet ensures stable network identities, persistent storage per pod, and ordered, deterministic scaling.
It uses filtering (Predicates → node fits requirements) and scoring (Priorities → best node) based on CPU/memory requests, taints/tolerations, affinity rules, resource pressure, etc.
PDB defines the minimum number of pods that must remain available during voluntary disruptions (e.g., node drain), preventing accidental downtime during maintenance.
Requests reserve resources for scheduling; limits define the maximum a container can use. Exceeding CPU → throttling; exceeding memory → OOMKilled.
Kubernetes enforces a flat, routable network where every Pod gets its own IP; CNI plugins (Cilium, Calico, Flannel, etc.) implement routing, NAT rules, and policies.
DaemonSets ensure a copy of a pod runs on every node (or matching nodes)—used for logs (FluentBit), monitoring agents (Node Exporter), or CNI components.
- ClusterIP: internal virtual IP
- NodePort: exposes on each node’s port
- LoadBalancer: provisions external LB from cloud provider and routes to nodes/ClusterIP.
It programs iptables/ipvs rules to route service traffic to the correct backend pods. Modern CNIs (Cilium) may replace kube-proxy entirely (kube-proxy replacement).
Taints repel pods from nodes; tolerations allow selected pods to be scheduled on those nodes. Used for node segregation (GPU nodes, infra nodes, etc.).
A webhook or built-in module that intercepts API requests—mutating (modify objects) or validating (approve or reject)—used for policies, sidecar injection, security.
etcd stores the entire Kubernetes cluster state—objects, configurations, secrets, node status. It must be backed up regularly and kept highly available.
HPA adjusts replica count based on metrics like CPU%, memory, or custom metrics via Metrics API, ensuring load-based scaling.
Ingress is the routing rule object; Ingress Controller is the implementation (NGINX, Traefik, AWS ALB controller) that translates rules into actual load balancer configuration.
Init containers run before the main container and guarantee startup order—used for migrations, waiting on dependencies, preparing config.
A container inside the same pod that extends the main app’s functionality (logging agent, service mesh proxy, file sync, etc.)
Secrets are stored in etcd and can be encrypted using EncryptionConfiguration with providers like AES-CBC, AES-GCM, or KMS (AWS KMS, GCP KMS).
Repeated container crashes caused by bad configs, missing files, failing health probes, or app-level exceptions; Kubernetes backs off with exponential delay.
- Liveness: restarts unhealthy containers
- Readiness: indicates when pod can receive traffic
- Startup: delays other probes until app is fully started
They control traffic at the pod level using labels; by default allow-all, but once a policy is applied, traffic becomes deny-all except what's explicitly allowed.
Deployment updates pods gradually using maxSurge/maxUnavailable, ensuring new pods become Ready before old ones terminate—supports automatic rollback on failure.
kubectl exec -it pod-name -- /bin/sh— get shell in podkubectl exec deploy/app -- env— run one-off command