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

You need to check TLS certificate expiry for 400 domains and alert at 21 days. How do you build it?

IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Simple but valuable check.

What I'd do →

  1. For each domain, open a TLS connection with ssl.create_default_context() and socket.create_connection((host, 443), timeout=5), wrap with server_hostname=host, read getpeercert()["notAfter"], parse with ssl.cert_time_to_seconds.
  2. Run concurrently with a thread pool.
  3. Report domains below 21 days; also report connection or verification failures.
  4. Or export as metrics and use blackbox_exporter's probe_ssl_earliest_cert_expiry.

Why → Expired certificates are a fully preventable outage.

Interview tip → Use SNI (server_hostname), or you get the wrong certificate on shared hosts.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation