You must drain and replace 50 Kubernetes nodes one at a time with Python, respecting PodDisruptionBudgets. How?
AdvancedScenarioKubernetes, Docker, SSH & fleet automation
Answer
Situation read → Controlled rolling node replacement.
What I'd do →
- For each node: cordon (
patch_node(name, {"spec": {"unschedulable": True}})). - Evict pods with the Eviction API (
create_namespaced_pod_eviction), skipping DaemonSet and mirror pods. A 429 response means a PDB is blocking; back off and retry. - Wait until the node has no evictable pods, then terminate the instance (ASG
terminate_instance_in_auto_scaling_groupwithShouldDecrementDesiredCapacity=False). - Wait for the replacement node to be
Readybefore continuing. - Prefer managed node group updates or Karpenter drift, which do this already.
Why → The Eviction API respects PDBs; deleting pods directly does not.
Interview tip → "Evict, don't delete" is the key line.
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 are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?AdvancedYou 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?Intermediate