Kubernetes
1. What is Kubernetes, and what problem does it solve?
- Orchestrate containerized application.
- Automate the deployment, scaling, and operations of containerized applications.
- Kubernetes automatically distributes containers, balances traffic, and restarts failed pod.
2. What are the main components of a Kubernetes cluster?
- A cluster has two main parts: the master node (control plane) and the worker nodes.
- Control plane include:
- API Server: Handles requests and serves as the cluster’s front-end.
- Controller Manager: Runs controllers to maintain desired state, like scaling pods.
- Scheduler: Assigns pods to nodes based on resources and policies.
- etcd: Stores cluster state as a key-value database.
- Worker nodes:
- Kubelet: Manages pods and ensures they run as expected.
- Kube-Proxy: Manages network policies and routes traffic.
- Container Runtime: Runs containers (e.g., Docker).
3. What is a Pod in Kubernetes, and how is it different from a container?
- Pod is the smallest deployable unit in Kubernetes.
- Unlike a container, which is a single isolated process, a Pod can run multiple containers, sharing the same IP and volumes.
4. Explain the role of Deployments, ReplicaSets, and Services in Kubernetes.
- Deployments
- Manage application updates and scalling ensuring smooth rollouts and rollbacks wihout downtime.
- ReplicaSets
- Ensure a specified number of pod replicas are running, controlled by Deployments.
- They maintain availability if pods fail.
- Services
- To expose pods over a network.
- Each pod gets it own IP address.
- Ingress
- As entrypoint for routing external traffic to services.
- Horizaontal Pod Autoscaler
- To automatically scale pods based on CPU or memory usage.
5. What is a Kubernetes Namespace, and why is it used?
- A Namespace is a virtual cluster within a Kubernetes cluster, used to organize and isolate resources like pods, services, and deployments.
- Separate environments (e.g., dev, prod) or teams in a shared cluster, preventing naming conflicts and enabling resource quotas.
- Resource Quotas: Limit resource usage within a namespace.
6. How does Kubernetes handle storage, and what are Persistent Volumes (PVs) and Persistent Volume Claims (PVCs)?
- Kubernetes manages storage using Persistent Volumes (PVs) and Persistent Volume Claims (PVCs).
- A PV is a cluster-wide storage resource, like an NFS share or cloud disk, provisioned manually or dynamically via StorageClasses.
- A PVC is a request by a user for storage, specifying size and access mode, which binds to a matching PV.
7. What is an Ingress, and how does it differ from a Service?
- A Kubernetes resource that manages external HTTP/HTTPS traffic, providing routing rules to direct requests to Services based on host or path.
- A Service, however, handles internal networking and load balancing for pods, typically within the cluster.
- For instance, I used an Ingress to route
example.com/api
to a backend Service, while the Service load-balanced traffic to multiple API pods.
8. How do you scale applications in Kubernetes?
- Horizontal Pod Autoscaling (HPA)
- Automatically adjusts pod replicas based on metrics like CPU or memory usage.
- Example: I set up HPA to scale a web app from 2 to 5 pods during high traffic.
- Cluster Autoscaling
- Adds or removes nodes based on resource needs.
- Manual Scaling
- Using
kubectl scale deployment my_app --replicas=4
to set a fixed number of pods.
- Using
9. What are ConfigMaps and Secrets, and how are they used?
-
ConfigMaps
- Store non-sensitive configuration data.
-
Secrets
- store sensitive data, like passwords or API keys.
-
Both can be mounted as volumes or injected as environment variables in pods.
10. How do you troubleshoot a pod that is in a CrashLoopBackOff state?
- To troubleshoot a CrashLoopBackOff pod,
- Check logs with
kubectl logs <pod_name>
to identify errors - Run
kubectl describe pod <pod_name>
to see events, such as resource limits or image pull issues. - Verify the pod’s configuration, like
command
orargs
in the YAML, for errors.
- Check logs with
11. Deployment Strategies
- Rolling Update: Replace pods one at a time, ensuring no downtime.
- Blue-Green Deployment
- Blue: Runs the current version of the app.
- Green: Runs the new version of the app.
- Once the green version is tested and ready, switch traffic to it.
- Want to test the new version thoroughly before switching traffic.
- Canary Deployment
- Deploy a new version to a small subset of users.
- Minimizes risk by testing on a small scale.