Perfect — I’ll make this “Kubernetes YAML Interview Cheatsheet” as a single, ready-to-use document.
You’ll get:
-
YAML – formatted and minimal so it’s easy to remember.
-
Real-Time Explanation – why it’s used in production.
-
Banking / Retail Analogy – to connect with Lloyds & PepsiCo use cases.
-
Common Interview Q&A – likely follow-up questions.
-
kubectl Commands – quick reference.
Kubernetes YAML Interview Cheatsheet
(Lloyds Bank & PepsiCo Ready)
- Persistent Volume (PV)
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-transaction-logs
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
storageClassName: manual
hostPath:
path: /mnt/data/transaction-logs
Real-Time Usage:
Stores transaction logs, invoices, or order data that must persist beyond pod restarts.
Banking Analogy:
Like a bank’s vault room—secure storage that exists even if the branch is renovated.
Common Q&A:
Q: Why PV over emptyDir?
A: emptyDir is temporary; PV survives pod restarts.
Q: Can multiple pods use this PV?
A: Yes, if ReadWriteMany mode is used.
kubectl:
kubectl apply -f pv.yaml
kubectl get pv
- Persistent Volume Claim (PVC)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-transaction-logs
spec:
accessModes:
- ReadWriteOnce
storageClassName: manual
resources:
requests:
storage: 10Gi
Real-Time Usage:
Apps request storage from available PVs.
Retail Analogy:
Like reserving a storage rack in a PepsiCo warehouse for a specific product.
Common Q&A:
Q: What happens if PVC size > PV size?
A: PVC stays Pending until a matching PV is available.
kubectl:
kubectl apply -f pvc.yaml
kubectl get pvc
- Pod
apiVersion: v1
kind: Pod
metadata:
name: debug-pod
spec:
containers:
- name: debug-container
image: busybox
command: ["sleep", "3600"]
Real-Time Usage:
Used for quick troubleshooting or running debug commands inside the cluster.
Banking Analogy:
Like sending a tech engineer inside the bank’s server room for a one-time fix.
Q&A:
Q: Why not a deployment?
A: A pod is lighter; used for temporary tasks.
kubectl:
kubectl apply -f pod.yaml
kubectl exec -it debug-pod -- sh
- Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: payment-service
spec:
replicas: 3
selector:
matchLabels:
app: payment
template:
metadata:
labels:
app: payment
spec:
containers:
- name: payment-container
image: myregistry/payment:v2
ports:
- containerPort: 8080
Real-Time Usage:
Manages multiple identical pods for a payment API.
Retail Analogy:
Like having 3 identical checkout counters—if one is down, others serve customers.
Q&A:
Q: How to rollback?
A: kubectl rollout undo deployment/payment-service.
kubectl:
kubectl apply -f deployment.yaml
kubectl rollout status deployment/payment-service
- Service
apiVersion: v1
kind: Service
metadata:
name: payment-service
spec:
selector:
app: payment
ports:
- port: 80
targetPort: 8080
type: ClusterIP
Real-Time Usage:
Internal stable access to the payment API.
Banking Analogy:
Like a fixed helpline number—even if backend staff changes, number stays same.
Q&A:
Q: Difference between ClusterIP & LoadBalancer?
A: ClusterIP is internal, LoadBalancer is public.
kubectl:
kubectl apply -f service.yaml
kubectl get svc
- ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: payment-config
data:
DB_HOST: "db-service"
MAX_RETRIES: "5"
Real-Time Usage:
Stores app configuration.
Retail Analogy:
Like a recipe card—tells the chef (app) how to cook without hardcoding.
kubectl:
kubectl create configmap payment-config --from-literal=DB_HOST=db-service
kubectl get configmap payment-config -o yaml
- Secret
apiVersion: v1
kind: Secret
metadata:
name: payment-secret
type: Opaque
data:
DB_PASSWORD: cGFzc3dvcmQ=
Real-Time Usage:
Stores sensitive info like DB passwords.
Banking Analogy:
Like storing ATM master PIN in a secure safe.
kubectl:
kubectl create secret generic payment-secret --from-literal=DB_PASSWORD=password
kubectl get secret payment-secret -o yaml
- Horizontal Pod Autoscaler (HPA)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: payment-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: payment-service
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
Real-Time Usage:
Auto-scales payment service when CPU > 60%.
Retail Analogy:
Like opening extra checkout counters during holiday rush.
kubectl:
kubectl apply -f hpa.yaml
kubectl get hpa
- Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: payment-ingress
spec:
rules:
- host: bank.example.com
http:
paths:
- path: /pay
pathType: Prefix
backend:
service:
name: payment-service
port:
number: 80
Real-Time Usage:
Routes /pay to payment API.
Banking Analogy:
Like routing customers entering a branch to the right department.
- NetworkPolicy
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-payment-to-db
spec:
podSelector:
matchLabels:
app: db
ingress:
- from:
- podSelector:
matchLabels:
app: payment
Real-Time Usage:
Restricts DB access to only payment pods.
Banking Analogy:
Like allowing only bank tellers (payment pods) to enter the vault (DB).
If you want, I can now put all this in a neat PDF with colored sections so you can print it or use on-screen during Lloyds & PepsiCo interviews, along with extra 5 tricky YAMLs (PodDisruptionBudget, StatefulSet, DaemonSet, CronJob, RoleBinding) that often surprise candidates.
Do you want me to create that expanded PDF version next?
No comments:
Post a Comment