Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

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 →

  1. Parse every file with yaml.safe_load_all, skipping empty docs; fail on YAML errors with file and line.
  2. Schema-validate with kubeconform (via subprocess), not by hand.
  3. Custom rules in Python: image tag not latest, resources set, runAsNonRoot: true, required labels, no hostPath.
  4. Output findings with file paths; exit non-zero on violations.
  5. 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.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation