Skip to main content
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. ──────────────────────────────────────────────

Listing Cluster Resources

If your Kubernetes cluster has multiple resources deployed, simply running:
will list the available resources. Using the alias, you can list all resources with:
To list resources across all namespaces, add the -A flag. This command displays pods, services, daemon sets, deployments, replica sets, jobs, and more:
──────────────────────────────────────────────

Exploring Namespaces and Deployments

First, list all namespaces in your cluster with:
To inspect the deployments in the User Acceptance Testing (uat) namespace, run:
──────────────────────────────────────────────

Inspecting a Deployment Manifest

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.
──────────────────────────────────────────────

Filtering Specific Information

Sometimes you only need to extract specific information from the manifest, such as the number of replicas. You have two options:
  1. Using grep:
    This method filters the YAML output for occurrences of the replicas field.
  2. Using JSONPath:
    For a cleaner output, use the JSONPath flag to extract just the value of replicas.
──────────────────────────────────────────────

Extracting Container Specifications

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:
This output displays all container configuration details defined in the Deployment. ──────────────────────────────────────────────

Summary

In summary, this article covered:
  • How to list cluster resources using kubectl get with or without namespaces.
  • Exploring namespaces and specific deployments in the cluster.
  • Inspecting detailed deployment manifests in YAML format.
  • Extracting specific information (like the number of replicas) using grep or JSONPath.
  • Retrieving container specifications directly from the deployment definition.
For more detailed information and advanced use cases, make sure to visit the official Kubernetes documentation.

Watch Video