Q26Docker build
What is a multi-stage Docker build?
A multi-stage build uses separate stages for compilation and runtime so build tools and intermediate files do not need to be included in the final image.
Answer
A multi-stage build uses separate stages for compilation and runtime so build tools and intermediate files do not need to be included in the final image.
Syntax
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /out
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /out .
ENTRYPOINT ["dotnet", "MyApi.dll"]
Example
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /out
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /out .
ENTRYPOINT ["dotnet", "MyApi.dll"]
Code example
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish -c Release -o /out
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /out .
ENTRYPOINT ["dotnet", "MyApi.dll"]
Diagram
Docker build → container/orchestrator operation → result
Key Points
- Reduces final image size and attack surface.
Q27Docker layers
How do image layers and build cache work?
Docker caches instructions and their inputs. If a step and its dependencies are unchanged, Docker may reuse that layer; order stable dependency steps before frequently changing sou
Answer
Docker caches instructions and their inputs. If a step and its dependencies are unchanged, Docker may reuse that layer; order stable dependency steps before frequently changing source files.
Syntax
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
Example
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
Code example
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
Diagram
Docker layers → container/orchestrator operation → result
Key Points
- A `.dockerignore` prevents irrelevant files entering the build context.
Q28Docker Compose
How can Compose run an API and database together?
Define each service and a named volume for database persistence. Use service DNS names for container-to-container traffic.
Answer
Define each service and a named volume for database persistence. Use service DNS names for container-to-container traffic.
Syntax
services:
api:
build: .
ports: ["8080:8080"]
environment:
DB_HOST: db
db:
image: postgres:16
environment:
POSTGRES_DB: app
POSTGRES_USER: app
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Example
services:
api:
build: .
ports: ["8080:8080"]
environment:
DB_HOST: db
db:
image: postgres:16
environment:
POSTGRES_DB: app
POSTGRES_USER: app
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Code example
services:
api:
build: .
ports: ["8080:8080"]
environment:
DB_HOST: db
db:
image: postgres:16
environment:
POSTGRES_DB: app
POSTGRES_USER: app
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Diagram
Docker Compose → container/orchestrator operation → result
Key Points
- Use a secrets manager or secure secret injection for production credentials.
Q29Docker networking
Compare bridge, host, and overlay networks.
Bridge networks connect containers on one Docker host. Host networking shares the host network namespace on supported platforms. Overlay networks connect services across hosts in c
Answer
Bridge networks connect containers on one Docker host. Host networking shares the host network namespace on supported platforms. Overlay networks connect services across hosts in compatible Docker setups.
Syntax
docker network create --driver bridge app-net
docker network ls
Example
docker network create --driver bridge app-net
docker network ls
Code example
docker network create --driver bridge app-net
docker network ls
Diagram
Docker networking → container/orchestrator operation → result
Key Points
- Choose the network model based on isolation and deployment topology.
Q30Image security
How do you reduce Docker image vulnerabilities?
Use trusted minimal base images, pin versions or digests, update dependencies, scan images, avoid secrets in layers, and run with least privilege.
Answer
Use trusted minimal base images, pin versions or digests, update dependencies, scan images, avoid secrets in layers, and run with least privilege.
Syntax
docker scout quickview my-image:1.0
docker image inspect my-image:1.0
Example
docker scout quickview my-image:1.0
docker image inspect my-image:1.0
Code example
docker scout quickview my-image:1.0
docker image inspect my-image:1.0
Diagram
Image security → container/orchestrator operation → result
Key Points
- Scanning helps; it does not prove an image is secure.
Q31Container limits
How do CPU and memory limits work in Docker?
Runtime flags constrain CPU scheduling and memory use. If memory exceeds its limit, the container may be killed by the kernel.
Answer
Runtime flags constrain CPU scheduling and memory use. If memory exceeds its limit, the container may be killed by the kernel.
Syntax
docker run --cpus=1.5 --memory=512m my-image
Example
docker run --cpus=1.5 --memory=512m my-image
Code example
docker run --cpus=1.5 --memory=512m my-image
Diagram
Container limits → container/orchestrator operation → result
Key Points
- Test limits under realistic load.
Q32Kubernetes architecture
What are the main control-plane components?
The API server exposes the Kubernetes API; etcd stores cluster state; the scheduler places Pods; and controller managers reconcile desired state.
Answer
The API server exposes the Kubernetes API; etcd stores cluster state; the scheduler places Pods; and controller managers reconcile desired state.
Syntax
kubectl get componentstatuses # legacy/deprecated in many clusters
kubectl get nodes
Example
kubectl get componentstatuses # legacy/deprecated in many clusters
kubectl get nodes
Code example
kubectl get componentstatuses # legacy/deprecated in many clusters
kubectl get nodes
Diagram
Kubernetes architecture → container/orchestrator operation → result
Key Points
- Managed Kubernetes may hide the control-plane infrastructure.
Q33Kubernetes scheduling
How does the scheduler choose a node?
The scheduler filters nodes against Pod constraints and then scores feasible nodes; the selected node is bound to the Pod.
Answer
The scheduler filters nodes against Pod constraints and then scores feasible nodes; the selected node is bound to the Pod.
Syntax
spec:
nodeSelector:
workload: general
Example
spec:
nodeSelector:
workload: general
Code example
spec:
nodeSelector:
workload: general
Diagram
Kubernetes scheduling → container/orchestrator operation → result
Key Points
- Affinity, taints/tolerations, resources, and topology can influence placement.
Q34Requests and limits
What is the difference between resource requests and limits?
Requests influence scheduling and represent expected resource needs. Limits cap resource use; CPU is throttled above its limit, while memory overage can trigger an OOM kill.
Answer
Requests influence scheduling and represent expected resource needs. Limits cap resource use; CPU is throttled above its limit, while memory overage can trigger an OOM kill.
Syntax
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
Example
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
Code example
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "1"
memory: "512Mi"
Diagram
Requests and limits → container/orchestrator operation → result
Key Points
- Set requests based on observed workload needs.
Q35Autoscaling
How does Horizontal Pod Autoscaler work?
HPA adjusts a workload's replica count based on observed metrics relative to targets, commonly CPU or memory utilization or custom metrics.
Answer
HPA adjusts a workload's replica count based on observed metrics relative to targets, commonly CPU or memory utilization or custom metrics.
Syntax
kubectl autoscale deployment api --min=2 --max=10 --cpu-percent=70
kubectl get hpa
Example
kubectl autoscale deployment api --min=2 --max=10 --cpu-percent=70
kubectl get hpa
Code example
kubectl autoscale deployment api --min=2 --max=10 --cpu-percent=70
kubectl get hpa
Diagram
Autoscaling → container/orchestrator operation → result
Key Points
- CPU utilization targets generally require CPU requests.
Q36Ingress
What is an Ingress?
Ingress defines HTTP and HTTPS routing rules from outside the cluster to Services. An Ingress controller must implement those rules.
Answer
Ingress defines HTTP and HTTPS routing rules from outside the cluster to Services. An Ingress controller must implement those rules.
Syntax
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app
spec:
ingressClassName: nginx
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
Example
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app
spec:
ingressClassName: nginx
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
Code example
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app
spec:
ingressClassName: nginx
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
Diagram
Ingress → container/orchestrator operation → result
Key Points
- Ingress is not itself the controller or load balancer.
Q37Service discovery
How do Pods discover other services?
Kubernetes DNS publishes names for Services. Clients use a Service DNS name rather than hard-coded Pod IPs.
Answer
Kubernetes DNS publishes names for Services. Clients use a Service DNS name rather than hard-coded Pod IPs.
Syntax
http://orders.default.svc.cluster.local:8080
Example
http://orders.default.svc.cluster.local:8080
Code example
http://orders.default.svc.cluster.local:8080
Diagram
Service discovery → container/orchestrator operation → result
Key Points
- Short names are namespace-relative; cross-namespace calls should use the target namespace.
Q38Rolling updates
How do you perform and verify a rollout?
Update the image or manifest, monitor rollout status, and use rollout history or undo if the release is unhealthy.
Answer
Update the image or manifest, monitor rollout status, and use rollout history or undo if the release is unhealthy.
Syntax
kubectl set image deployment/api api=registry.example.com/api:2.0
kubectl rollout status deployment/api
kubectl rollout undo deployment/api
Example
kubectl set image deployment/api api=registry.example.com/api:2.0
kubectl rollout status deployment/api
kubectl rollout undo deployment/api
Code example
kubectl set image deployment/api api=registry.example.com/api:2.0
kubectl rollout status deployment/api
kubectl rollout undo deployment/api
Diagram
Rolling updates → container/orchestrator operation → result
Key Points
- Use immutable version tags or digests.
Q39Stateful workloads
When should you use a StatefulSet?
A StatefulSet provides stable Pod identities and ordered deployment/scaling semantics, commonly paired with persistent volume claims for stateful systems.
Answer
A StatefulSet provides stable Pod identities and ordered deployment/scaling semantics, commonly paired with persistent volume claims for stateful systems.
Syntax
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: database
spec:
serviceName: database
replicas: 3
selector:
matchLabels: {app: database}
template:
metadata:
labels: {app: database}
spec:
containers:
- name: db
image: postgres:16
Example
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: database
spec:
serviceName: database
replicas: 3
selector:
matchLabels: {app: database}
template:
metadata:
labels: {app: database}
spec:
containers:
- name: db
image: postgres:16
Code example
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: database
spec:
serviceName: database
replicas: 3
selector:
matchLabels: {app: database}
template:
metadata:
labels: {app: database}
spec:
containers:
- name: db
image: postgres:16
Diagram
Stateful workloads → container/orchestrator operation → result
Key Points
- A StatefulSet alone does not make a database highly available.
Q40Persistent storage
How does PersistentVolumeClaim work?
A PVC requests storage capacity and access modes. Kubernetes binds it to a suitable PersistentVolume or provisions storage through a StorageClass.
Answer
A PVC requests storage capacity and access modes. Kubernetes binds it to a suitable PersistentVolume or provisions storage through a StorageClass.
Syntax
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 10Gi
Example
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 10Gi
Code example
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 10Gi
Diagram
Persistent storage → container/orchestrator operation → result
Key Points
- Storage semantics depend on the CSI driver and storage provider.
Q41Configuration rollout
What happens when a ConfigMap changes?
Environment variables sourced from a ConfigMap do not update inside existing processes automatically. Mounted ConfigMap files may update eventually, but the application must reload
Answer
Environment variables sourced from a ConfigMap do not update inside existing processes automatically. Mounted ConfigMap files may update eventually, but the application must reload them.
Syntax
kubectl rollout restart deployment/api
Example
kubectl rollout restart deployment/api
Code example
kubectl rollout restart deployment/api
Diagram
Configuration rollout → container/orchestrator operation → result
Key Points
- Use a checksum annotation or controlled rollout to restart Pods after config changes.
Q42Secrets management
How should production credentials be supplied to Pods?
Use a managed secret store or a controlled Kubernetes Secret workflow, limit access with RBAC, enable encryption at rest, rotate credentials, and avoid logging them.
Answer
Use a managed secret store or a controlled Kubernetes Secret workflow, limit access with RBAC, enable encryption at rest, rotate credentials, and avoid logging them.
Syntax
kubectl create secret generic db-creds --from-file=password=./db-password.txt
Example
kubectl create secret generic db-creds --from-file=password=./db-password.txt
Code example
kubectl create secret generic db-creds --from-file=password=./db-password.txt
Diagram
Secrets management → container/orchestrator operation → result
Key Points
- Never commit secret files or print them in CI logs.
Q43Network policy
What is a NetworkPolicy?
A NetworkPolicy specifies allowed ingress and egress traffic for selected Pods, but it requires a network plugin that enforces policies.
Answer
A NetworkPolicy specifies allowed ingress and egress traffic for selected Pods, but it requires a network plugin that enforces policies.
Syntax
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-api
spec:
podSelector:
matchLabels:
app: api
policyTypes: [Ingress]
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
Example
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-api
spec:
podSelector:
matchLabels:
app: api
policyTypes: [Ingress]
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
Code example
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-api
spec:
podSelector:
matchLabels:
app: api
policyTypes: [Ingress]
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
Diagram
Network policy → container/orchestrator operation → result
Key Points
- Policies are additive; verify default-deny and DNS needs.
Q44RBAC
How does Kubernetes RBAC work?
Roles define permissions on resources; RoleBindings grant those permissions within a namespace. ClusterRoles and ClusterRoleBindings can grant cluster-scoped permissions.
Answer
Roles define permissions on resources; RoleBindings grant those permissions within a namespace. ClusterRoles and ClusterRoleBindings can grant cluster-scoped permissions.
Syntax
kubectl create role pod-reader --verb=get,list,watch --resource=pods -n staging
kubectl create rolebinding reader-binding --role=pod-reader --user=developer -n staging
Example
kubectl create role pod-reader --verb=get,list,watch --resource=pods -n staging
kubectl create rolebinding reader-binding --role=pod-reader --user=developer -n staging
Code example
kubectl create role pod-reader --verb=get,list,watch --resource=pods -n staging
kubectl create rolebinding reader-binding --role=pod-reader --user=developer -n staging
Diagram
RBAC → container/orchestrator operation → result
Key Points
- Prefer least privilege and review service-account permissions.
Q45Probes
How do startup, readiness, and liveness probes differ?
Startup probes give slow-starting applications time to initialize. Readiness controls whether traffic is sent to a Pod. Liveness detects stuck processes and can trigger restarts.
Answer
Startup probes give slow-starting applications time to initialize. Readiness controls whether traffic is sent to a Pod. Liveness detects stuck processes and can trigger restarts.
Syntax
startupProbe:
httpGet: {path: /health/startup, port: 8080}
failureThreshold: 30
periodSeconds: 5
livenessProbe:
httpGet: {path: /health/live, port: 8080}
periodSeconds: 10
Example
startupProbe:
httpGet: {path: /health/startup, port: 8080}
failureThreshold: 30
periodSeconds: 5
livenessProbe:
httpGet: {path: /health/live, port: 8080}
periodSeconds: 10
Code example
startupProbe:
httpGet: {path: /health/startup, port: 8080}
failureThreshold: 30
periodSeconds: 5
livenessProbe:
httpGet: {path: /health/live, port: 8080}
periodSeconds: 10
Diagram
Probes → container/orchestrator operation → result
Key Points
- A startup probe suppresses liveness/readiness until startup succeeds.
Q46Pod disruption
What is a PodDisruptionBudget?
A PDB limits voluntary disruptions by specifying a minimum available or maximum unavailable number of Pods during supported eviction workflows.
Answer
A PDB limits voluntary disruptions by specifying a minimum available or maximum unavailable number of Pods during supported eviction workflows.
Syntax
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: api-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: api
Example
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: api-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: api
Code example
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: api-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: api
Diagram
Pod disruption → container/orchestrator operation → result
Key Points
- A PDB does not prevent all involuntary failures.
Q47Jobs and CronJobs
When do you use Job and CronJob?
A Job runs Pods to completion. A CronJob creates Jobs on a schedule for recurring tasks such as reports, cleanup, or backups.
Answer
A Job runs Pods to completion. A CronJob creates Jobs on a schedule for recurring tasks such as reports, cleanup, or backups.
Syntax
apiVersion: batch/v1
kind: CronJob
metadata:
name: cleanup
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: cleanup
image: busybox:1.36
command: ["sh", "-c", "echo cleanup"]
Example
apiVersion: batch/v1
kind: CronJob
metadata:
name: cleanup
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: cleanup
image: busybox:1.36
command: ["sh", "-c", "echo cleanup"]
Code example
apiVersion: batch/v1
kind: CronJob
metadata:
name: cleanup
spec:
schedule: "0 2 * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: cleanup
image: busybox:1.36
command: ["sh", "-c", "echo cleanup"]
Diagram
Jobs and CronJobs → container/orchestrator operation → result
Key Points
- Make scheduled tasks idempotent and consider concurrency policy.
Q48Helm
What is Helm?
Helm packages Kubernetes resources into charts with templates, values, and release history, helping teams configure and deploy applications consistently.
Answer
Helm packages Kubernetes resources into charts with templates, values, and release history, helping teams configure and deploy applications consistently.
Syntax
helm upgrade --install my-app ./chart -f values-prod.yaml
helm list -A
Example
helm upgrade --install my-app ./chart -f values-prod.yaml
helm list -A
Code example
helm upgrade --install my-app ./chart -f values-prod.yaml
helm list -A
Diagram
Helm → container/orchestrator operation → result
Key Points
- Review rendered manifests and secret handling before deploying.
Q49Observability
How do you monitor Kubernetes workloads?
Collect metrics, logs, and traces; monitor resource saturation, error rates, latency, restarts, scheduling failures, and rollout health.
Answer
Collect metrics, logs, and traces; monitor resource saturation, error rates, latency, restarts, scheduling failures, and rollout health.
Syntax
kubectl top nodes
kubectl top pods -A
kubectl get events -A --sort-by=.lastTimestamp
Example
kubectl top nodes
kubectl top pods -A
kubectl get events -A --sort-by=.lastTimestamp
Code example
kubectl top nodes
kubectl top pods -A
kubectl get events -A --sort-by=.lastTimestamp
Diagram
Observability → container/orchestrator operation → result
Key Points
- `kubectl top` needs a functioning metrics pipeline.
Q50Troubleshooting
A Pod is stuck in CrashLoopBackOff. What do you check?
Inspect current and previous logs, Pod events, startup command, configuration, mounted files, probes, permissions, and memory limits. Fix the cause before repeatedly restarting it.
Answer
Inspect current and previous logs, Pod events, startup command, configuration, mounted files, probes, permissions, and memory limits. Fix the cause before repeatedly restarting it.
Syntax
kubectl logs <pod> --previous
kubectl describe pod <pod>
kubectl get events --sort-by=.lastTimestamp
Example
kubectl logs <pod> --previous
kubectl describe pod <pod>
kubectl get events --sort-by=.lastTimestamp
Code example
kubectl logs <pod> --previous
kubectl describe pod <pod>
kubectl get events --sort-by=.lastTimestamp
Diagram
Troubleshooting → container/orchestrator operation → result
Key Points
- CrashLoopBackOff is a backoff status, not the root cause.
Q51Troubleshooting
A Pod is stuck in Pending. What do you check?
Check events for insufficient CPU or memory, unbound PVCs, node selectors, affinity, taints, quota, and unavailable nodes.
Answer
Check events for insufficient CPU or memory, unbound PVCs, node selectors, affinity, taints, quota, and unavailable nodes.
Syntax
kubectl describe pod <pod>
kubectl get nodes
kubectl get pvc -A
Example
kubectl describe pod <pod>
kubectl get nodes
kubectl get pvc -A
Code example
kubectl describe pod <pod>
kubectl get nodes
kubectl get pvc -A
Diagram
Troubleshooting → container/orchestrator operation → result
Key Points
- Scheduling events usually point to the blocking constraint.
Q52Troubleshooting
A Service cannot reach its Pods. How do you debug it?
Verify selectors and Pod labels, EndpointSlices, target ports, readiness, DNS, network policies, and whether the application listens on the expected interface.
Answer
Verify selectors and Pod labels, EndpointSlices, target ports, readiness, DNS, network policies, and whether the application listens on the expected interface.
Syntax
kubectl get svc <service> -o yaml
kubectl get endpointslice -l kubernetes.io/service-name=<service>
kubectl get pods --show-labels
Example
kubectl get svc <service> -o yaml
kubectl get endpointslice -l kubernetes.io/service-name=<service>
kubectl get pods --show-labels
Code example
kubectl get svc <service> -o yaml
kubectl get endpointslice -l kubernetes.io/service-name=<service>
kubectl get pods --show-labels
Diagram
Troubleshooting → container/orchestrator operation → result
Key Points
- A Service with no ready endpoints commonly indicates a selector or readiness issue.
Q53Image distribution
What causes ImagePullBackOff?
Typical causes include a wrong image name or tag, missing registry credentials, network/DNS issues, rate limits, or an unsupported architecture.
Answer
Typical causes include a wrong image name or tag, missing registry credentials, network/DNS issues, rate limits, or an unsupported architecture.
Syntax
kubectl describe pod <pod>
kubectl create secret docker-registry regcred --docker-server=registry.example.com --docker-username=<user> --docker-password=<token>
Example
kubectl describe pod <pod>
kubectl create secret docker-registry regcred --docker-server=registry.example.com --docker-username=<user> --docker-password=<token>
Code example
kubectl describe pod <pod>
kubectl create secret docker-registry regcred --docker-server=registry.example.com --docker-username=<user> --docker-password=<token>
Diagram
Image distribution → container/orchestrator operation → result
Key Points
- Attach registry credentials through imagePullSecrets or a service account.
Q54Deployment strategies
Compare Recreate and RollingUpdate strategies.
Recreate terminates existing Pods before creating new ones and may cause downtime. RollingUpdate gradually replaces Pods within configured surge and unavailable limits.
Answer
Recreate terminates existing Pods before creating new ones and may cause downtime. RollingUpdate gradually replaces Pods within configured surge and unavailable limits.
Syntax
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
Example
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
Code example
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
Diagram
Deployment strategies → container/orchestrator operation → result
Key Points
- Capacity and readiness determine whether zero-downtime rollout is achievable.
Q55Docker and Kubernetes
Show the path from source code to running Pods.
A CI pipeline tests and builds the image, pushes it to a registry, then deployment automation applies Kubernetes manifests that create and manage Pods.
Answer
A CI pipeline tests and builds the image, pushes it to a registry, then deployment automation applies Kubernetes manifests that create and manage Pods.
Syntax
Source -> CI tests -> Docker build -> Image registry
|
v
Manifest / Helm -> Kubernetes API -> Deployment -> Pods
Example
Source -> CI tests -> Docker build -> Image registry
|
v
Manifest / Helm -> Kubernetes API -> Deployment -> Pods
Code example
Source -> CI tests -> Docker build -> Image registry
|
v
Manifest / Helm -> Kubernetes API -> Deployment -> Pods
Diagram
Docker and Kubernetes → container/orchestrator operation → result
Key Points
- Keep build and deployment permissions scoped separately.
Q79Docker Images
Why use a multi-stage Docker build?
Multi-stage builds separate compilation from the runtime image. Copy only required artifacts from the build stage to reduce image size and avoid
Answer
Multi-stage builds separate compilation from the runtime image. Copy only required artifacts from the build stage to reduce image size and avoid shipping compilers or build dependencies unnecessarily.
Example: SDK build stage → publish artifacts → lean runtime stage
Diagram / flow: Builder image → compiled/published output → runtime image
Syntax
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
# build app
FROM mcr.microsoft.com/dotnet/aspnet:8.0
COPY --from=build /out .
Example
SDK build stage → publish artifacts → lean runtime stage
Code example
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
# build app
FROM mcr.microsoft.com/dotnet/aspnet:8.0
COPY --from=build /out .
Diagram
Builder image → compiled/published output → runtime image
Key Points
- Multi-stage builds separate compilation from the runtime image.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q80Container Security
Why should a container run as a non-root user?
A non-root process reduces the impact of a compromised application. Use an appropriate user in the image and ensure file permissions, mounted vol
Answer
A non-root process reduces the impact of a compromised application. Use an appropriate user in the image and ensure file permissions, mounted volumes, and required ports support that user.
Example: Image starts process as unprivileged user → reduced container-level privileges
Diagram / flow: Docker image → USER app → application process
Example
Image starts process as unprivileged user → reduced container-level privileges
Diagram
Docker image → USER app → application process
Key Points
- A non-root process reduces the impact of a compromised application.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q81Container Operations
How does Docker HEALTHCHECK work?
HEALTHCHECK runs a command to report container health. It can expose a failing application process even when the container is still running; orch
Answer
HEALTHCHECK runs a command to report container health. It can expose a failing application process even when the container is still running; orchestration behavior and restart decisions should be configured separately.
Example: Container running → health probe → healthy or unhealthy status
Diagram / flow: Docker engine executes probe → records health status
Syntax
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8080/health || exit 1
Example
Container running → health probe → healthy or unhealthy status
Code example
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost:8080/health || exit 1
Diagram
Docker engine executes probe → records health status
Key Points
- HEALTHCHECK runs a command to report container health.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q83Networking
When would you use bridge, host, or none networking?
Bridge networking provides an isolated network with container connectivity; host networking shares the host network namespace on supported platfo
Answer
Bridge networking provides an isolated network with container connectivity; host networking shares the host network namespace on supported platforms; none disables normal network connectivity. Choose based on isolation and platform needs.
Example: Container → selected network mode → available interfaces and routes
Diagram / flow: Bridge: isolated network; host: host network; none: no standard network
Syntax
docker network create app-net
docker run --network app-net myapp
Example
Container → selected network mode → available interfaces and routes
Code example
docker network create app-net
docker run --network app-net myapp
Diagram
Bridge: isolated network; host: host network; none: no standard network
Key Points
- Bridge networking provides an isolated network with container connectivity; host networking shares the host network namespace on supported platforms; none disables normal network connectivity.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q84Docker Compose
How can Compose wait for a dependency health check?
Compose can use a health check on a dependency and a condition such as service_healthy where supported. This helps startup ordering but does not
Answer
Compose can use a health check on a dependency and a condition such as service_healthy where supported. This helps startup ordering but does not replace application-level retries after startup.
Example: Database starts → health check passes → dependent service starts
Diagram / flow: Compose dependency graph + health status controls startup order
Syntax
depends_on:
db:
condition: service_healthy
Example
Database starts → health check passes → dependent service starts
Code example
depends_on:
db:
condition: service_healthy
Diagram
Compose dependency graph + health status controls startup order
Key Points
- Compose can use a health check on a dependency and a condition such as service_healthy where supported.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q85Container Operations
How do CPU and memory limits protect a host?
Resource limits prevent one container from consuming unbounded host resources. Memory limits can lead to OOM termination; CPU limits throttle exe
Answer
Resource limits prevent one container from consuming unbounded host resources. Memory limits can lead to OOM termination; CPU limits throttle execution, so tune limits using measured workloads.
Example: Container workload → cgroup limits → bounded CPU/memory consumption
Diagram / flow: Configured limits → kernel enforcement → throttle or OOM behavior
Syntax
docker run --memory=512m --cpus=1.5 myapp
Example
Container workload → cgroup limits → bounded CPU/memory consumption
Code example
docker run --memory=512m --cpus=1.5 myapp
Diagram
Configured limits → kernel enforcement → throttle or OOM behavior
Key Points
- Resource limits prevent one container from consuming unbounded host resources.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q87Container Security
How should secrets be supplied to containers?
Avoid baking credentials into image layers or committing them to source control. Use an appropriate secret manager or orchestrator secret mechani
Answer
Avoid baking credentials into image layers or committing them to source control. Use an appropriate secret manager or orchestrator secret mechanism, restrict access, rotate credentials, and avoid logging secret values.
Example: Secret manager → authorized runtime injection → application
Diagram / flow: Secret store → controlled delivery → process; never embed secret in image
Syntax
docker run --env-file local-dev.env myapp # local development only
Example
Secret manager → authorized runtime injection → application
Code example
docker run --env-file local-dev.env myapp # local development only
Diagram
Secret store → controlled delivery → process; never embed secret in image
Key Points
- Avoid baking credentials into image layers or committing them to source control.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q88Observability
How should container logs be collected?
Applications should generally write structured logs to stdout/stderr, while a platform or logging driver collects, routes, and retains them. Set
Answer
Applications should generally write structured logs to stdout/stderr, while a platform or logging driver collects, routes, and retains them. Set retention and rotation limits to prevent disk exhaustion.
Example: Application stdout/stderr → runtime logging driver → central log platform
Diagram / flow: Container logs → collector/driver → searchable log store
Syntax
docker logs <container>
docker run --log-opt max-size=10m --log-opt max-file=3 myapp
Example
Application stdout/stderr → runtime logging driver → central log platform
Code example
docker logs <container>
docker run --log-opt max-size=10m --log-opt max-file=3 myapp
Diagram
Container logs → collector/driver → searchable log store
Key Points
- Applications should generally write structured logs to stdout/stderr, while a platform or logging driver collects, routes, and retains them.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q91Kubernetes Operations
How do readiness, liveness, and startup probes differ?
Readiness controls whether a Pod receives traffic; liveness detects a stuck container and may trigger restart; startup gives slow-starting applic
Answer
Readiness controls whether a Pod receives traffic; liveness detects a stuck container and may trigger restart; startup gives slow-starting applications time before other probes begin. Probe endpoints should reflect distinct purposes.
Example: Startup probe succeeds → readiness gates traffic; liveness checks ongoing health
Diagram / flow: Startup → readiness for routing; liveness for restart decisions
Syntax
readinessProbe:
httpGet: { path: /ready, port: 8080 }
Example
Startup probe succeeds → readiness gates traffic; liveness checks ongoing health
Code example
readinessProbe:
httpGet: { path: /ready, port: 8080 }
Diagram
Startup → readiness for routing; liveness for restart decisions
Key Points
- Readiness controls whether a Pod receives traffic; liveness detects a stuck container and may trigger restart; startup gives slow-starting applications time before other probes begin.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q93Kubernetes Scheduling
How do CPU and memory requests differ from limits?
Requests influence scheduling and represent expected resource allocation; limits cap usage. CPU excess is throttled, while exceeding a memory lim
Answer
Requests influence scheduling and represent expected resource allocation; limits cap usage. CPU excess is throttled, while exceeding a memory limit can cause OOM termination. Correct values require observation under load.
Example: Scheduler uses requests → kubelet/runtime enforces limits
Diagram / flow: Requests affect placement; limits constrain runtime use
Syntax
resources:
requests: { cpu: "100m", memory: "128Mi" }
limits: { cpu: "500m", memory: "512Mi" }
Example
Scheduler uses requests → kubelet/runtime enforces limits
Code example
resources:
requests: { cpu: "100m", memory: "128Mi" }
limits: { cpu: "500m", memory: "512Mi" }
Diagram
Requests affect placement; limits constrain runtime use
Key Points
- Requests influence scheduling and represent expected resource allocation; limits cap usage.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q94Kubernetes Scaling
How does a Horizontal Pod Autoscaler work?
HPA adjusts workload replicas based on configured metrics such as CPU utilization or custom/external metrics. Resource requests and metrics avail
Answer
HPA adjusts workload replicas based on configured metrics such as CPU utilization or custom/external metrics. Resource requests and metrics availability matter; scaling policies and stabilization help avoid flapping.
Example: Metrics → HPA controller → desired replicas → Deployment/ReplicaSet
Diagram / flow: Metric target exceeded → increase replicas; below target → scale down subject to policy
Syntax
kubectl autoscale deployment web --min=2 --max=10 --cpu-percent=70
Example
Metrics → HPA controller → desired replicas → Deployment/ReplicaSet
Code example
kubectl autoscale deployment web --min=2 --max=10 --cpu-percent=70
Diagram
Metric target exceeded → increase replicas; below target → scale down subject to policy
Key Points
- HPA adjusts workload replicas based on configured metrics such as CPU utilization or custom/external metrics.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q95Kubernetes Deployments
How do rolling updates reduce application downtime?
A Deployment gradually replaces old Pods with new ones based on maxSurge and maxUnavailable. Readiness probes and adequate capacity are important
Answer
A Deployment gradually replaces old Pods with new ones based on maxSurge and maxUnavailable. Readiness probes and adequate capacity are important; incompatible database changes can still break a rollout.
Example: Create new Pods → wait until ready → terminate old Pods
Diagram / flow: Deployment rollout uses readiness and surge/unavailable settings
Syntax
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
Example
Create new Pods → wait until ready → terminate old Pods
Code example
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
Diagram
Deployment rollout uses readiness and surge/unavailable settings
Key Points
- A Deployment gradually replaces old Pods with new ones based on maxSurge and maxUnavailable.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.
Q99Kubernetes Networking
What is the role of Ingress or Gateway API?
Ingress and Gateway API describe HTTP(S) routing from outside a cluster to services, subject to a compatible controller or implementation. They d
Answer
Ingress and Gateway API describe HTTP(S) routing from outside a cluster to services, subject to a compatible controller or implementation. They do not automatically provide routing without that implementation.
Example: External client → ingress/gateway controller → Service → Pods
Diagram / flow: Host/path rules → controller → backend service
Syntax
host: example.com
http:
paths: ...
Example
External client → ingress/gateway controller → Service → Pods
Code example
host: example.com
http:
paths: ...
Diagram
Host/path rules → controller → backend service
Key Points
- Ingress and Gateway API describe HTTP(S) routing from outside a cluster to services, subject to a compatible controller or implementation.
- Test the behavior in a representative environment.
- Consider security, reliability, and operational impact.