You are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?
AdvancedScenarioKubernetes, Docker, SSH & fleet automation
Answer
Situation read → Event-driven reconciliation; watches can drop and expire.
What I'd do →
- Consider whether a mutating admission policy or Kyverno rule does this declaratively; usually it does.
- If code is needed, use
kopf(handles watches, retries, and resumption) or a watch loop that lists first, reconciles all, then watches from the list'sresourceVersion. - Handle
410 Goneby re-listing, and reconnect on timeouts. - Patch idempotently (only if the label is missing).
- Run in-cluster with a service account allowed only
get, list, watch, patchon namespaces.
Why → Level-triggered reconciliation (look at all current state) survives missed events.
Interview tip → Say "level-triggered, not edge-triggered" and mention 410 Gone.
More on Kubernetes, Docker, SSH & fleet automation
You need a report of every pod in the cluster with no CPU or memory limits. How do you write it?BeginnerYou need to restart all Deployments in a namespace that reference a rotated Secret. How?AdvancedYour CI runners keep running out of disk because of Docker images. Write a cleanup plan in Python.IntermediateYou need to run `df -h` on 300 Linux hosts and list any above 85%. Python or Ansible?BeginnerA Python script SSHes to hosts with `AutoAddPolicy`. Security says that is unacceptable. What do you change?IntermediateYou want to validate all Kubernetes manifests in a repo in CI with Python. What would the script check?Intermediate