How to format the output of kubectl describe to JSON
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
kubectl describe is designed for human-readable diagnostics, not machine parsing. If you need JSON for scripts, dashboards, or automation, the correct approach is to query the same resource with kubectl get -o json and optionally combine it with field filtering. Understanding this distinction prevents brittle parsing pipelines.
Why describe Cannot Be Reliably Converted
kubectl describe prints formatted text that mixes sections, nested lists, and event tables. The exact layout can vary by Kubernetes version and resource type. Text scraping this output with ad hoc regular expressions is fragile and usually breaks during upgrades.
Instead of converting describe output, fetch the resource object directly:
This returns stable JSON fields under metadata, spec, and status, which are intended for API consumers.
Map Common describe Needs to JSON Queries
Most information people seek in describe already exists in structured fields.
Pod images and restart counts:
Related reading
- how to found the Killed reason of the app in kubernetes pods
- How to generate YAML template with kubectl command?
- How to get a custom healthcheck path in a GCE L7 balancer serving a Kubernetes Ingress?
- How to get a PDF/print version of kubernetes' docs?
- How to get all Kubernetes pod IP in each pods?
- how to get container host machine ip address and container name in EKS
- How to get current date in Helm
- How to get current namespace from running pod usin client api

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.