You want to validate all Kubernetes manifests in a repo in CI with Python. What would the script check?
IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer
Situation read → Policy checks on YAML before it reaches the cluster.
What I'd do →
- Parse every file with
yaml.safe_load_all, skipping empty docs; fail on YAML errors with file and line. - Schema-validate with
kubeconform(viasubprocess), not by hand. - Custom rules in Python: image tag not
latest, resources set,runAsNonRoot: true, required labels, nohostPath. - Output findings with file paths; exit non-zero on violations.
- Consider Conftest/Kyverno CLI to share the same policies with the cluster.
Why → Catching policy violations at PR time is cheaper than at admission time.
Interview tip → Mention reusing the same policies in CI and in-cluster.
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