Kubernetes is an open-source container orchestration platform developed by Google, now maintained by the Cloud Native Computing Foundation (CNCF).
It automates the deployment, scaling, and management of containerized applications — whether on AWS, Azure, GCP, or on-prem.
In DevOps, Kubernetes is the backbone for:
Answer:
Kubernetes (K8s) is an orchestration system for managing containerized applications across clusters of servers.
It automates:
Why it’s used in DevOps:
It eliminates manual container management and provides a consistent, declarative way to deploy apps across environments — especially when scaling microservices.
Answer:
A Pod is the smallest deployable unit in Kubernetes — it encapsulates one or more containers that share:
Example:
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
spec:
containers:
- name: nginx
image: nginx:latest
In real-world use:
Each microservice runs in its own Pod, often managed by higher-level controllers like Deployments.
Answer:
| Component | Role |
|---|---|
| Master Node (Control Plane) | Manages cluster state and decisions (scheduling, scaling) |
| Worker Node | Runs application workloads (Pods) |
Core control plane components:
Answer:
A ReplicaSet ensures that a specified number of Pod replicas are running at any given time.
Example:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-rs
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: nginx
image: nginx
If a Pod crashes, ReplicaSet automatically replaces it — enabling high availability.
Answer:
A Deployment is a higher-level abstraction that manages ReplicaSets and Pods declaratively.
Benefits:
Example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
spec:
replicas: 3
template:
spec:
containers:
- name: nginx
image: nginx:latest
In real-world CI/CD:
Developers update container versions via Deployment manifests for zero-downtime rollouts.
Answer:
A Service provides stable network access to a set of Pods.
Pods are ephemeral — they come and go — but Services give them a consistent endpoint.
Types of Services:
Example:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- port: 80
targetPort: 80
kubectl and what is it used for?Answer:
kubectl is the command-line tool used to interact with Kubernetes clusters.
Common commands:
kubectl get pods
kubectl describe pod myapp-pod
kubectl logs myapp-pod
kubectl apply -f deployment.yaml
In CI/CD:
kubectl commands are automated within Jenkins or GitHub Actions pipelines to deploy workloads.
Answer:
Namespaces logically isolate cluster resources.
They’re used to:
Example:
kubectl create namespace dev
kubectl apply -f deployment.yaml -n dev
In production:
Namespaces help teams share clusters securely.
Answer:
Both inject configuration data into Pods:
Example (Secret):
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
password: bXlwYXNzd29yZA== # base64 encoded
Answer:
A DaemonSet ensures that a Pod runs on every node (or subset).
Use cases:
Example:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-monitor
spec:
template:
spec:
containers:
- name: node-exporter
image: prom/node-exporter
Answer:
| Feature | Deployment | StatefulSet |
|---|---|---|
| Pod Identity | Stateless | Stable network identity |
| Storage | Shared (non-persistent) | Persistent Volume Claims |
| Use Case | Web servers, APIs | Databases, Kafka, Redis |
Example:
Use a StatefulSet for a MongoDB cluster, ensuring consistent pod names and persistent volumes.
Answer:
You can expose apps using:
Example Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-ingress
spec:
rules:
- host: app.cloudnukes.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapp-service
port:
number: 80
In DevOps:
Ingress is the preferred method for production environments.
Answer:
Kubernetes Services act as internal load balancers using kube-proxy.
It routes traffic evenly across Pods using round-robin by default.
For external traffic, it integrates with cloud load balancers (ELB, GCLB).
Answer:
Use rolling updates with Deployments:
kubectl set image deployment/myapp myapp=nginx:v2
To monitor rollout:
kubectl rollout status deployment/myapp
If issues occur:
kubectl rollout undo deployment/myapp
In production:
This ensures zero downtime during version upgrades.
Answer:
Example:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
In AWS:
You can dynamically provision EBS volumes through a StorageClass.
Answer:
kubectl rollout restart deployment myapp
This restarts Pods one by one, ensuring continuous availability.
Answer:
kubectl logs mypod
kubectl logs --previous mypod
kubectl describe pod mypod
Common causes: image pull errors, OOM kills, CrashLoopBackOff.
Answer:
Define resource limits and requests:
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
In production:
This prevents a single Pod from consuming all cluster resources — improving stability.
Answer:
Options:
Example:
helm install myapp -f values-prod.yaml
Answer:
kubectl or Helm.Example Jenkinsfile:
stage('Deploy') {
steps {
sh 'kubectl apply -f k8s/deployment.yaml'
}
}
Answer:
Kubernetes continuously monitors system state through controllers.
If a Pod or Node fails:
This ensures high availability without manual intervention.
Answer:
Used to check container health:
Example:
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
readinessProbe:
tcpSocket:
port: 8080
periodSeconds: 5
In production:
Prevents traffic from routing to unready or crashed containers.
Answer:
Manual:
kubectl scale deployment myapp --replicas=5
Auto-scaling (HPA):
kubectl autoscale deployment myapp --min=2 --max=10 --cpu-percent=80
Why important:
Ensures apps scale dynamically based on load — essential for cost optimization and resilience.
Answer:
In production:
Monitoring is critical to detect failing Pods, resource bottlenecks, and latency issues.
Answer:
Example:
apiVersion: kubernetes-client.io/v1
kind: ExternalSecret
metadata:
name: db-secret
spec:
backendType: secretsManager
data:
- key: prod/db/password
name: DB_PASSWORD
Answer:
Blue-Green:
Deploy two versions side by side, then switch traffic using Services or Ingress.
Canary:
Gradually shift traffic using Istio or Argo Rollouts.
Example (Canary):
spec:
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
Real-world:
Used for safe, progressive deployments with minimal downtime.
Answer:
NotReady after 5 mins (default).In AWS:
Use Managed Node Groups (EKS) or Auto Scaling to replace unhealthy nodes automatically.
CrashLoopBackOff error?Answer:
kubectl logs pod-name
kubectl describe pod pod-name
Q: Your Pods were continuously restarting with CrashLoopBackOff. How did you resolve it?
Answer (STAR):
kubectl logs to check errors — found “Port already in use.”Deployment.yaml.Q: You noticed high latency in a Kubernetes application after scaling. How did you investigate it?
Answer (STAR):