This article explains how to use the kubectl get command to inspect Kubernetes cluster resources effectively.
In this article, we explore how to use the kubectl get command to inspect your Kubernetes cluster resources. For convenience, an alias (k) for kubectl is used in the examples below. If you haven’t already, enable shell autocompletion for a smoother workflow.Below you’ll find a detailed walkthrough of various commands and options to inspect your cluster effectively.──────────────────────────────────────────────
If your Kubernetes cluster has multiple resources deployed, simply running:
Copy
Ask AI
kubectl get
will list the available resources. Using the alias, you can list all resources with:
Copy
Ask AI
controlplane ~ ➜ alias k=kubectlcontrolplane ~ ➜ k get allNAME READY STATUS RESTARTS AGEpod/logs-generator 1/1 Running 4 40mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 136mcontrolplane ~ ➜
To list resources across all namespaces, add the -A flag. This command displays pods, services, daemon sets, deployments, replica sets, jobs, and more:
controlplane ~ ➜ k get nsNAME STATUS AGEdefault Active 137mdev Active 40mingress-nginx Active 40mkube-node-lease Active 137mkube-public Active 137mkube-system Active 137mmonitoring Active 40mqa Active 40mstaging Active 40mtest Active 40muat Active 40m
To inspect the deployments in the User Acceptance Testing (uat) namespace, run:
Copy
Ask AI
controlplane ~ ➜ k get -n uat deployments.appsNAME READY UP-TO-DATE AVAILABLE AGEnotes-app-deployment 2/2 2 2 41m
To review a detailed deployment configuration (for example, “notes-app-deployment”), output the full manifest in YAML format. This manifest mirrors the original configuration file that created the Deployment:
This YAML output includes all key details such as metadata, specifications, and container configurations.
The manifest output closely resembles the original file used for deployment creation, making it an excellent reference for understanding the resource structure.
To delve deeper into a deployment’s container specifications (such as image, ports, and resource requests), use JSONPath. Since the container configurations are nested under spec.template.spec.containers, running the command below will provide the necessary details: