Advanced Level
This section covers expert-level concepts in Docker and Kubernetes, including security best practices, advanced architecture patterns, and complex deployment strategies.
Docker Advanced Questions
How do namespaces and cgroups actually implement containers?
Containers are not virtual machines — they are ordinary Linux processes boxed in by two kernel features:
- Namespaces provide isolation — each namespace type hides a resource view: PID (container sees only its processes), NET (own interfaces/iptables), MNT (own filesystem mount tree), UTS (own hostname), IPC, USER (uid mapping, root inside ≠ root outside)
- Cgroups (v2) provide limits and accounting — CPU shares/quota, memory caps (the OOM killer works here), PID limits, I/O bandwidth
bashThe expert conclusion this leads to: "container escape" and isolation weaknesses come from the shared kernel — namespaces are not a security boundary on par with VMs. That's precisely why hardened deployments reach for user namespaces, seccomp/AppArmor/SELinux profiles, and stronger boundaries (gVisor/Kata — see the sandboxing question).
What are the differences between Docker volumes, bind mounts, and tmpfs?
Expert nuances to add:
- Named volumes survive
docker rmof the container (decoupled lifecycle) and work cross-platform; bind mounts tie you to host layout and UID/permission mismatches (the classic "created files are root-owned" problem — avoid in production) :roflags matter (-v config.yaml:/etc/app/config.yaml:ro)- In Kubernetes this maps to PersistentVolumes (volume-ish, cluster objects), hostPath (bind-mount-ish — avoid unless privileged), and emptyDir (tmpfs-ish with
medium: Memory)
- Named volumes survive
How do you sandbox containers beyond Docker's defaults?
When shared-kernel isolation isn't enough (multi-tenant platforms, running untrusted code), strengthen the boundary:
- Rootless Docker/Podman — the daemon and containers run as an unprivileged user with user namespaces; daemon compromise no longer means root on the host. Podman additionally drops the central daemon entirely
- gVisor (runsc) — a user-space application kernel intercepting syscalls; containers get a partially reimplemented Linux kernel, sharply reducing the syscall attack surface. Ideal for untrusted workloads (FaaS platforms like Google Cloud Run use it)
- Kata Containers — lightweight per-pod/pod-group micro-VMs: hardware-level isolation with container UX; the strong boundary for hostile multi-tenancy
- Defense-in-depth regardless —
--cap-drop=ALL(add back only what's needed), read-only rootfs (--read-only), seccomp profiles (Docker's default blocks ~44 syscalls; stricter profiles exist), AppArmor/SELinux, no--privileged(it disables nearly every safeguard)
The selection logic to state: default seccomp+caps-drop covers most apps; gVisor for untrusted code where kernel vulns are the threat; Kata where regulatory or tenant isolation demands hardware boundaries.
How do you secure a Docker container in production?
Layered hardening, from build to runtime:
- Build — minimal/distroless bases, pinned digests (
FROM x@sha256:...), multi-stage builds, no secrets in layers, scan images (Trivy/Grype) as a CI gate - Runtime identity — run as non-root (
USER 10001),--cap-drop=ALL(add--cap-addonly for specifics),--read-onlyrootfs with writable volumes only where needed - Runtime boundaries — seccomp profile (default or stricter), AppArmor/SELinux,
--pids-limit, no--privileged, nodocker.sockmounted into containers (a container with the daemon socket is effectively host root) - Network — user-defined networks with least reachability, egress filtering, no cross-network shortcuts
- Operations — sign images (cosign) and verify before deploy, immutable tags, periodic base-image rebuilds (CVE patches), and log/monitor container activity (Falco for runtime threats)
The one-liner summary: minimal image, unprivileged process, read-only filesystem, dropped capabilities, no socket, signed supply chain — then prove it with scanning at every stage.
- Build — minimal/distroless bases, pinned digests (
What is Docker Content Trust, and what replaced it?
Docker Content Trust (DCT) used The Update Framework (TUF) to sign images — a client pushes signed tags, and clients with
DOCKER_CONTENT_TRUST=1refuse unsigned pulls.The current-state answer interviewers want: DCT is effectively deprecated/legacy (Notary v1 is unmaintained), and the ecosystem has moved to Sigstore/cosign:
bash- Cosign advantages — signatures stored in the registry alongside the image (no separate Notary server), keyless signing via OIDC (Sigstore's Fulcio/Rekor transparency log), native Kubernetes admission integration
- The full pipeline pattern — CI signs the image after scanning → admission controller (Kyverno/Gatekeeper/policy) verifies the signature before allowing the pod → unsigned images cannot run in the cluster
- Pair with SLSA provenance (attesting how/where the image was built) for supply-chain completeness — provenance + signature + SBOM is the modern triad
How do you implement container image scanning in a pipeline?
Scan at every stage where a vulnerability can be caught early:
- Static/image scanning — Trivy (fast, comprehensive, free), Grype;
trivy image --severity CRITICAL,HIGH --exit-code 1 myapp:1.4.2fails the build on critical findings - Dependency scanning — Snyk/Dependabot for the app's packages (image scanners see OS packages well but app-language deps better in source)
- Registry/rescanning — scan on push, rescan periodically (CVEs are discovered after images ship — Harbor and cloud registries automate this)
- Policy the results into action — severity thresholds, suppression with expiry for accepted risks, and admission-time re-verification so unscanned/failed images can't run
bashThe operational wisdom:
--ignore-unfixed(no patch exists → don't block forever), track fixable-CVE trends per image rather than raw counts, and rebuild images regularly on fresh bases — the base image you scanned last month has new CVEs today.- Static/image scanning — Trivy (fast, comprehensive, free), Grype;
How do you optimize Docker layer caching in CI pipelines?
CI rebuilds are where caching wins or loses minutes on every commit:
- Registry-backed cache — BuildKit imports/exports layers to a registry:
docker buildx build --cache-from type=registry,ref=myapp:cache --cache-to type=inline— so a fresh runner starts warm - GitHub Actions cache backend —
--cache-to type=gha/--cache-from type=gha - Local volume cache on persistent runners — keep
/var/lib/buildkitacross builds (with periodic pruning) - Correct Dockerfile ordering — dependency layers before source (invalidate rarely), source last
- Cache mounts for package managers —
RUN --mount=type=cache,target=/root/.npm npm cikeeps downloads across rebuilds even when the layer is invalidated - Parallel stages — BuildKit runs independent stages concurrently; structure Dockerfiles so lint/test stages don't serialize the build
The measurement to mention: p95 build time, and cache hit ratio — a build that "works but never hits cache" is usually a context problem (un-ignored files churning the
COPY . .layer).- Registry-backed cache — BuildKit imports/exports layers to a registry:
How do you secure Docker networking?
- User-defined networks, not the default bridge — embedded DNS, per-network isolation; unrelated apps live on separate networks
- Segmentation by tier — db network reachable only by the API network; frontend can't touch the database network at all
- Encrypt overlay traffic —
docker network create --driver overlay --opt encryptedfor multi-host (Swarm) east-west traffic - Egress control — containers can reach the internet by default; filter with iptables on the host or run egress-restricted networks for sensitive workloads
- The Docker-specific gaps to name — published ports (
-p) bypass some firewall tooling via iptables NAT (a host-port exposed to 0.0.0.0 may bypass your perimeter — bind to127.0.0.1and front with a proxy); and the container socket rule: nothing mountsdocker.sockuntrusted, because that socket is the host
The Kubernetes contrast: these hand-built rules become NetworkPolicies — declarative, default-deny east-west traffic — which is why network security is easier to standardize on K8s than on raw Docker.
What are Docker secrets, and what are their limits?
Docker (Swarm) Secrets are managed secret storage: secrets are stored encrypted in the Swarm Raft log and mounted into the container as an in-memory tmpfs file (
/run/secrets/<name>) — never as an env var, never on disk, never in the image:bash- Strengths — no env-var exposure (
docker inspectcan't read them), no image layer leak, at-rest encryption in the Swarm store - The limit to state clearly — secrets are a Swarm-only feature; plain
docker runhas no equivalent (tmpfs mounts are the manual approximation:--mount type=tmpfs,destination=/run/secrets)
The production reality: most teams orchestrate with Kubernetes, where the equivalents are Kubernetes Secrets (enable etcd encryption + RBAC), External Secrets Operator / Vault Agent (secrets stay in Vault/cloud managers, clusters hold references), or sealed secrets for GitOps-safe storage. The principle that transfers everywhere: inject at runtime as files, never env vars or image layers.
- Strengths — no env-var exposure (
How do you troubleshoot a container that has no shell or no tools?
Minimal/distroless images have no
sh, nops, no debugging tools — which breaks the usualdocker execworkflow. The toolbox:bash--pid container:X/--network container:X— a toolbox container sharing the target's process and network views (netshoot carries nslookup, tcpdump, curl, ss)- Host-side kernel view:
docker top,/proc/<pid>/inspection, cgroup stats - For K8s the equivalent is
kubectl debug -it pod --image=busybox(ephemeral containers) - The prevention note: ship a deliberate debug strategy — a
-debugimage variant, an init-container toolbox, or documented ephemeral-container commands — because you will need to tcpdump a distroless pod at 3 a.m.
Kubernetes Advanced Questions
Explain the Kubernetes control plane architecture in depth.
- API server (kube-apiserver) — the only component that talks to etcd; everything (kubectl, controllers, kubelets) reads/writes through it. Horizontally scalable; pipelines requests through authentication → authorization (RBAC) → admission webhooks → validation → persistence
- etcd — the distributed key-value store holding all cluster state; Raft-consensus quorum (3 or 5 members). The cluster's memory — back it up (etcd snapshots or managed control planes) and watch its disk latency (API slowness is usually etcd)
- Scheduler — watches for pods with no
nodeName; filters feasible nodes (resources, taints/tolerations, affinity, topology spread) and scores the best fit. Customizable via scheduling frameworks - Controller manager — runs the reconciliation controllers (Deployments→ReplicaSets→Pods, node lifecycle, endpoints, jobs) — each comparing desired vs actual state through the API server, with leader election for HA
The worker-side trio completes the picture: kubelet (node agent running pods + probes), kube-proxy (Service VIP/iptables/IPVS rules), container runtime (containerd via CRI). Optionally the cloud controller manager integrates cloud LBs/routes. The architecture summary to deliver: declarative state in etcd + independent controllers reconciling through one API — every HA, RBAC, and upgrade decision follows from that shape.
What are Kubernetes RBAC, and how do you design them?
RBAC answers "who can do what, to which resources" — four objects:
yaml- Role/RoleBinding are namespace-scoped; ClusterRole/ClusterRoleBinding are cluster-wide (nodes, PVs, namespaces themselves)
- Subjects — Users/Groups (humans via OIDC) and ServiceAccounts (workloads) — the CI/deployer access pattern is a dedicated SA with a minimal RoleBinding
- Design practices — start from the audit question ("what does this identity actually need?"), use
kubectl auth can-i --listto verify, prefer Roles over ClusterRoles, and never bindcluster-adminto humans routinely - The gotcha worth naming — default SAs in a namespace can be over-privileged (automounted tokens); disable
automountServiceAccountTokenwhere a pod needs no API access
What are admission controllers, and how do you use them for policy?
Admission controllers are webhooks the API server calls after authn/authz and before persistence — the last chance to mutate or reject a request:
- MutatingAdmissionWebhook — modifies objects: inject sidecars (Istio), add defaults, label enforcement
- ValidatingAdmissionWebhook — accept/reject: policy checks on the final object
yaml- Policy engines — Kyverno (Kubernetes-native YAML policies, friendlier) and OPA Gatekeeper (Rego, broader scope) replace hand-written webhooks: policies as versioned code with audit mode first, then enforce
- What they enable in CI/CD — only-signed-images admission (cosign verification), no-
latest-tags, mandatory labels/limits/probes, namespace-level protections - The reliability caveat — webhooks are on the critical path for API writes: keep them highly available, fail-open vs fail-closed deliberately, and watch webhook latency (a slow webhook slows the whole API server)
What is a NetworkPolicy, and how do you implement zero-trust networking in Kubernetes?
By default, all pods can reach all pods — NetworkPolicy adds declarative east-west traffic control (implemented by the CNI plugin — Calico, Cilium; not by vanilla kube-proxy):
yaml- Default deny first — a policy selecting pods with no rules blocks all traffic to them; build up from there
- Labels as identity — policies target pods by label, so access control follows deployments automatically
- DNS/egress gotcha — default-deny egress breaks DNS; allow port 53 to kube-dns explicitly
- Layered security to name: NetworkPolicy (L3/L4) + mTLS identity (service mesh, L7 identity) + ingress gateway controls = the zero-trust pod network; Cilium adds L7 filtering (HTTP paths) via eBPF
The common failure to mention: teams adopt a CNI without NetworkPolicy support (flannel) and discover their policies are silently no-ops — verify enforcement with a test pod.
What are PodDisruptionBudgets, PriorityClasses, and ResourceQuotas for?
The three "operational safety" objects, each answering a different disruption question:
- PodDisruptionBudget (PDB) — protects against voluntary disruptions (node drains, upgrades):
minAvailable: 2ormaxUnavailable: 1for the app's selector. Kubernetes blocks or waits on drains that would violate it — the reason cluster upgrades coexist with running services. (Note: it does not protect against involuntary failures — that's replicas + anti-affinity.) - PriorityClass — orders scheduling and eviction: critical system components get high priority and preempt lower ones under node pressure; pair with
preemptionPolicy - ResourceQuota / LimitRange — namespace-level spend control: total CPU/memory/pod counts per namespace (Quota) and per-container defaults/ceiling (LimitRange) — how you stop one team's runaway job from starving the cluster
Together they encode operational policy: who may be disrupted, who preempts whom, and how much any team may consume — the trio that turns a shared cluster into a fair, upgradeable platform.
- PodDisruptionBudget (PDB) — protects against voluntary disruptions (node drains, upgrades):
How do you write a Kubernetes custom controller/Operator?
The Operator pattern: a Custom Resource Definition (CRD) extends the API with your domain object; a controller watches it and reconciles real infrastructure toward it:
yaml- Frameworks — Kubebuilder / Operator SDK (Go, controller-runtime): declare a reconciler, watch the CR, and requeue on changes
- The reconcile loop —
Reconcile()is level-triggered, not edge-triggered: read desired spec → read actual state → compute the diff → act → update status → return (requeue or done). It must be idempotent, because it runs on every relevant change and periodically - What Operators encode — the operational runbook as code: provisioning, failover, backup schedules, version upgrades with migration steps (Prometheus Operator, Postgres Operators, Strimzi for Kafka)
- Best practices — status conditions with observedGeneration, ownerReferences for garbage collection, careful finalizers for external cleanup, and rate-limited requeues to avoid API storms
The summary to deliver: Operators are how the operate in DevOps becomes code — the controller manager pattern, applied to your own domain.
How does a service mesh work in Kubernetes (Istio example)?
A mesh moves service-to-service concerns out of application code into the platform:
- Data plane — Envoy sidecars (or eBPF/ambient mode) intercept every pod's traffic via iptables redirection
- Control plane (istiod) — distributes config, certificates (workload mTLS identity), and routing rules to the sidecars
- Traffic management — VirtualServices/DestinationRules: retries, timeouts, circuit breaking, and weighted version routing — the primitive behind canary releases:
yaml- Security — automatic mTLS between workloads with SPIFFE-style identities, plus
AuthorizationPolicyfor L7 allow-lists — zero-trust without touching app code - Observability — every hop's rate/errors/latency emitted by the sidecar, giving per-version metrics that canary analysis consumes
The honest cost line (from intermediate to expert): operational weight — control-plane upgrades, sidecar resource tax, debugging a new layer — which is why ambient (sidecar-less) modes and the question "do we need this at our scale?" belong in the answer.
How do you implement GitOps in Kubernetes end to end?
GitOps: Git holds declared desired state; an in-cluster controller continuously reconciles:
- Tooling — Argo CD (app-of-apps, UI, drift visualization) or Flux (lightweight, modular); both support Kustomize/Helm sources, RBAC-aware sync, and automated/hooked sync policies
- Repository topology — app repos (code + CI that builds/pushes images) separate from the config repo (manifests the operator watches); CI bumps the image tag as its final commit; the operator syncs — CI never touches the cluster directly
- App-of-apps — a root Application that manages all other Applications: onboarding a new service is a PR to the config repo
- Safety mechanics — sync waves for ordering (CRDs → operators → apps), automated pruning (deleted from Git = deleted from cluster), drift alerts (don't auto-correct everything — some drift should page a human), and secrets via SOPS+KMS, Sealed Secrets, or External Secrets Operator
- Rollback —
git revert+ sync (or Argo's rollback UI in emergencies, then fix Git — the repo must remain the truth)
The architecture payoff to state: the cluster's entire desired state is reviewable, revertible, and continuously verified — "what is running and why" is always answerable by reading a repository.
How do you upgrade a Kubernetes cluster safely?
Upgrades are routine operations that expose every HA shortcut you took — the process matters more than the version delta:
- Order of operations — one minor version at a time (n-1 → n), control plane first, then nodes; components are version-skew compatible only within that window (kubelets may lag the API server by up to 3 minors, but don't)
- Workload safety first — PodDisruptionBudgets verified, replicas spread across nodes, everything in Git (rebuildable), stateful workloads' failover tested
- The loop per node — cordon → drain (PDB governs) → upgrade kubelet/containerd → uncordon → verify pods healthy → next node; managed services (EKS/AKS/GKE) automate the control plane but the node-pool loop is still yours
- Before production — a staging cluster upgrade,
kubectl deprecations/API-diff checks (removed APIs are the classic breakage — v1.22/1.25/1.26 each removed API groups), and addon/chart compatibility verified - Rollback reality — control-plane rollbacks are limited/unsupported; the real rollback is your workloads: GitOps reapplies n-1 manifests, and etcd backups restore the cluster (test restores)
The expert framing: upgrades are safe when the cluster is rebuildable from code — clusters with hand-maintained state are the ones that never get upgraded, and un-upgraded clusters are the security incidents of next year.
What is etcd's role in the cluster, and how do you operate it?
etcd is the cluster's source of truth: every object — pods, secrets, RBAC, CRDs — is a key-value record under
/registry/. Lose etcd reliably = lose the cluster.- Consistency model — Raft consensus: writes need quorum, so a 5-member cluster survives 2 failures; odd member counts only
- Performance sensitivity — every API write and watch hits etcd; large clusters are etcd workloads: watch out for slow disks (etcd demands low fsync latency), unbounded event/CRD churn, and too-large objects (1 MB limit, ~1.5 MB recommended max)
- Operations — compaction (history trimming) + defrag run and monitored; scheduled snapshots (
etcdctl snapshot save) and tested restores; TLS everywhere; etcd on dedicated, fast (NVMe) disks separate from everything else - Managed clusters (EKS/AKS/GKE) — the provider operates etcd, but the shared-responsibility insight stands: you still own the data — backup manifests/CRDs (Velero for volume+resource snapshots) because the provider's etcd SLA does not restore your specific objects
The diagnostic to name: "API server slow / 504s" → check etcd fsync and commit latencies first (
etcdctl endpoint health,--write-out=table) — it's the most common hidden cause on self-managed clusters.
Contribute & Stay Updated
Want to contribute? We welcome contributions! If you have insights, new tools, or improvements, feel free to submit a pull request.
How to Contribute?
- Read the CONTRIBUTING.md guide.
- Fix errors, add missing topics, or suggest improvements.
- Submit a pull request with your updates.
Community & Support
GitHub: @NotHarshhaa Blog: ProDevOpsGuy Telegram Community: Join Here