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:-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: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: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:-
Using grep:
This method filters the YAML output for occurrences of thereplicasfield. -
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 underspec.template.spec.containers, running the command below will provide the necessary details:
Summary
In summary, this article covered:- How to list cluster resources using
kubectl getwith 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.