DevOps, Docker, Kubernetes & CI/CD questions
Walk through troubleshooting and design scenarios.
By Invicly Tech, , in Interview Preparation. About 13 minutes to read.
In short
DevOps interviews are scenario-driven: debug a failing pod, design a pipeline, handle an outage. Show a calm, step-by-step method and explain the trade-offs of each tool.
Explained simply
DevOps interviews feel different from coding rounds. Instead of a puzzle, you get a story: the site is down, a pod keeps restarting, or the team wants faster releases. The interviewer wants to see how you think when things are uncertain.
A good answer follows a calm method. First gather facts with real commands. Then form a guess about the cause. Then test it and fix it. Say each step out loud, including the commands you would type, so the interviewer can follow your reasoning.
You also need to know the tools well enough to explain how they work inside. What is a Docker layer? How do two containers talk to each other? What does Kubernetes do when a probe fails? These details turn a generic answer into a convincing one.
Finally, show judgement. Every choice has a cost. Blue-green gives instant rollback but doubles your servers. A long CI pipeline catches more bugs but slows everyone down. Naming the trade-off is often what separates a senior answer from a junior one.
Press Play on a diagram to walk through it one step at a time.
- 1kubectl get pods
See restarts and status
- 2kubectl describe pod
Events, exit code, OOMKilled, probe failures
- 3kubectl logs --previous
Logs from the crashed container
- 4Check config
Env vars, secrets, image tag, resource limits
- 5Fix or roll back
Redeploy, or kubectl rollout undo
- Replace pods gradually
- Kubernetes default
- Old and new versions mix briefly
- Two full environments
- Switch traffic at once
- Instant rollback, double cost
- Small % of traffic to new version
- Watch metrics, then widen
- Limits blast radius
- maxSurge: extra pods allowed, default 25%
- maxUnavailable: pods allowed down, default 25%
- Readiness probe gates each new pod
- kubectl rollout undo to go back
- Shift 5%, then 25%, then 100% of traffic
- Needs a mesh or ingress that splits traffic
- Automatic analysis of error rate and latency
- Argo Rollouts or Flagger are common
In depth
Docker images and layers under the hood
An image is a stack of read-only layers plus a config (entrypoint, environment, exposed ports). In a Dockerfile, RUN, COPY and ADD each create a filesystem layer; instructions like ENV and CMD only change the config. Layers are identified by a hash of their content and shared between images, so ten images built FROM the same base store that base once.
When a container starts, Docker adds a thin writable layer on top, using the overlay2 storage driver. Reads fall through to the first layer that has the file. Writing to a file from a lower layer first copies it up into the writable layer. Deleting a file only hides it, so a file removed in a later RUN still makes the image bigger.
The build cache reuses a layer if the instruction and its inputs have not changed, and every layer after a changed one is rebuilt. That is why you copy the dependency file and install dependencies before copying the source code.
- Multi-stage builds: compile in one stage, copy only the result into a small runtime image
- docker history image shows the size of each layer
- Use .dockerignore to keep .git and node_modules out of the build context
- Put rm in the same RUN that created the files, or they stay in an earlier layer
Container networking in one picture
By default, containers join the bridge network. Docker creates a virtual bridge (docker0) on the host and gives each container a private IP and a virtual ethernet pair. Outbound traffic is NATed through the host. Inbound traffic needs a published port: -p 8080:80 forwards host port 8080 to port 80 in the container.
On the default bridge, containers cannot find each other by name. On a user-defined bridge network (docker network create app), Docker runs an embedded DNS server, so the api container can reach the db container at db:5432. Docker Compose creates such a network for you, which is why service names just work there.
Other modes: host shares the host's network stack (no isolation, no port mapping needed, Linux only in practice) and none gives no network at all. In Kubernetes, all containers in one pod share a network namespace, so they talk over localhost, and every pod gets its own IP.
- 1Client
Calls host-ip:8080
- 2Host port mapping
-p 8080:80 rule, NAT to the container
- 3Bridge network
Virtual switch on the host
- 4Container eth0
Private IP like 172.18.0.3
- 5App on port 80
Must listen on 0.0.0.0, not 127.0.0.1
Reading exit codes and pod states
When a container stops, its exit code tells you a lot. 0 means it finished, which still causes restarts if a Deployment expects a long-running process. 1 is a generic application error, so read the logs. 127 means the command was not found, often a typo in the entrypoint or a missing binary in a slim image. 137 is 128 + 9 (SIGKILL), usually the kernel OOM killer when the container passes its memory limit; describe shows Reason: OOMKilled. 143 is 128 + 15 (SIGTERM), a normal stop request.
CrashLoopBackOff is not an error by itself; it means the container keeps exiting and the kubelet waits longer between restarts: 10 seconds, doubling up to a 5 minute cap. A failing liveness probe also causes restarts, so check probe settings when the app starts slowly. Other states point elsewhere: ImagePullBackOff means a wrong image name or missing registry credentials, Pending is usually a scheduling problem, and CreateContainerConfigError is often a missing ConfigMap or Secret.
- kubectl describe pod: Last State, Reason, Exit Code, Events
- kubectl logs pod --previous: output of the crashed run
- kubectl get events --sort-by=.lastTimestamp: recent cluster events
Designing a CI/CD pipeline out loud
Start from goals: fast feedback for developers, the same artifact promoted through every environment, and a safe, quick path to roll back. Then describe stages. On every pull request: lint, unit tests and a build, ideally under ten minutes. On merge to main: build the image once, tag it with the commit SHA, scan it for vulnerabilities, push to a registry, deploy to staging, run integration or smoke tests. Production deploys use the same image, behind a manual approval or automatically with a canary.
Mention the details that show experience: cache dependencies between runs, run independent jobs in parallel, keep secrets in the CI secret store or fetch them with OIDC instead of long-lived keys, and never rebuild per environment, because then you test one thing and ship another. With GitOps tools like Argo CD, the pipeline only updates the image tag in a Git repo, and the cluster pulls the change.
- 1Pull request
Lint, unit tests, build
- 2Merge to main
Build image, tag with commit SHA
- 3Scan and push
Vulnerability scan, push to registry
- 4Staging
Deploy, smoke and integration tests
- 5Production
Same image, approval or canary
Handling a production outage scenario
Interviewers want structure, not heroics. 1. Acknowledge and assess impact: which users, how many, since when. Check dashboards for the four golden signals: latency, traffic, errors and saturation. 2. Communicate early: open an incident channel, name an incident commander, post status updates. 3. Find what changed. Most outages follow a deploy, a config change, a certificate expiry or a traffic spike. 4. Mitigate first: roll back, scale up, disable a feature flag or fail over. Restoring service beats finding the root cause. 5. Resolve and verify the metrics are back to normal. 6. Write a blameless postmortem with a timeline, root cause, what went well and action items with owners.
Use SLOs to talk about impact: if the SLO is 99.9% availability per month, the error budget is about 43 minutes of downtime, and this incident spent part of it.
- Mitigate first, investigate second
- Ask: what changed in the last hour?
- 99.9% monthly availability allows about 43 minutes of downtime
Learn it in 5 short steps
About 1h 10m each. Track them with a timer in your plan.
- 1Explain Docker images, layers and networking~1h 10m
- 2Debug a CrashLoopBackOff pod~1h 10m
- 3Design a CI/CD pipeline aloud~1h 10m
- 4Walk through a production outage scenario~1h 10m
- 5Compare deployment strategies like blue-green and canary~1h 10m
Key points
- Docker images are stacks of cached layers; order Dockerfile steps from stable to changing.
- Exit code 137 usually means the container was OOMKilled.
- A good pipeline: lint, test, build image, scan, deploy to staging, then production.
- In outages, mitigate first (roll back), then find the root cause and write a postmortem.
Key terms
Tap a card to flip it. 0/5 known
Examples
kubectl get pods -n shop
kubectl describe pod api-7d9f -n shop # events, exit code, OOMKilled?
kubectl logs api-7d9f -n shop --previous # logs from the crashed run
kubectl get events -n shop --sort-by=.lastTimestamp
kubectl rollout undo deployment/api -n shop # roll back a bad releaseShrinking a 1.2 GB Python image
Interview prompt: our image is huge and builds slowly. Step 1: check docker history to see which layers are big. Step 2: start from a slim base instead of the full one. Step 3: copy requirements.txt first and install, so code changes do not reinstall dependencies. Step 4: use --no-cache-dir so pip does not keep its download cache in the layer. Step 5: run as a non-root user. Step 6: add a .dockerignore for .git, tests and local venvs. The result is often a few hundred megabytes and rebuilds in seconds when only code changes.
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN useradd --create-home app
USER app
EXPOSE 8000
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]Latency spike after a deploy
Scenario: p99 latency jumped from 200 ms to 3 seconds ten minutes after a release. Step 1: check impact on the dashboard, error rate is flat but latency is high. Step 2: correlate with the deploy time, it matches. Step 3: mitigate by rolling back the Deployment, and confirm latency recovers. Step 4: now investigate calmly: compare the diff, check slow query logs and traces. Suppose a new query lacks an index. Step 5: fix with an index, add a load test to CI, and write the postmortem. Saying rollback before root cause is the key point.
kubectl rollout history deployment/api -n shop
kubectl rollout undo deployment/api -n shop
kubectl rollout status deployment/api -n shop
kubectl top pods -n shop # CPU and memory per pod
kubectl logs deploy/api -n shop --since=15m | grep -i slowQuick reference
- RUN, COPY and ADD create layers; order Dockerfile steps from rarely changed to often changed
- User-defined bridge networks give DNS by container name; the default bridge does not
- Exit 137 = SIGKILL, often OOMKilled; 143 = SIGTERM; 127 = command not found
- CrashLoopBackOff delay doubles from 10 s up to a 5 minute cap
- Build the image once, tag it with the commit SHA, promote the same image to every environment
- In an outage: assess, communicate, find what changed, mitigate, then find root cause
- Rolling update defaults: maxSurge 25% and maxUnavailable 25%
Common mistakes
- Guessing at causes before reading events and previous logs.
- Describing tools without trade-offs, such as canary versus blue-green cost.
- Fixing forward during an outage when a rollback is faster.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Run nginx with port 8080 on your machine mapped to port 80 in the container, then find the container's IP and its exit code after you stop it.
- Exercise 2medium
Create a pod that gets OOMKilled on purpose, then use kubectl to prove why it died.
- Exercise 3hard
Write a short outline answer for: design a CI/CD pipeline for 20 microservices in one monorepo, deploying to Kubernetes.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is the difference between CMD and ENTRYPOINT?
- ENTRYPOINT sets the executable that always runs, and CMD gives default arguments that docker run can override. If only CMD is set, the whole command can be replaced at run time.
- What is the difference between a liveness and a readiness probe?
- A failing liveness probe makes the kubelet restart the container. A failing readiness probe only removes the pod from Service endpoints, so it stops receiving traffic without being restarted.
- Canary or blue-green: which is better?
- Neither always wins. Blue-green is simpler and rolls back instantly but needs double capacity; canary limits risk with real traffic and needs traffic splitting and good metrics.
- How do I practise DevOps scenario questions?
- Break things on purpose in a local cluster like kind or minikube: wrong image tags, low memory limits, failing probes, missing secrets. Then practise diagnosing each one aloud with kubectl.