The kubectl get
command is a fundamental tool in Kubernetes for retrieving information about resources. This comprehensive guide will explore various uses of the get
command across different Kubernetes resources.
1. List all pods in the current namespace:
kubectl get pods
This command retrieves a list of all pods running in the current namespace. The output includes details such as name, status, and age of each pod.
Verification: To verify, check if the list of pods matches the expected pods in your cluster using kubectl get pods
.
2. Display detailed information about a specific pod:
kubectl get pod
This command retrieves detailed information about a specific pod in YAML format. It includes all configurations and status information of the pod.
Verification: Use kubectl describe pod
to cross-check specific details like container statuses and events.
3. List all services across all namespaces:
kubectl get services --all-namespaces
This command lists all services in all namespaces. It’s useful for getting a global view of services deployed across the Kubernetes cluster.
Verification: Check the service list across namespaces using kubectl get services --all-namespaces
.
4. List all nodes along with additional details:
kubectl get nodes -o wide
By adding the -o wide
option, this command displays additional information such as internal IP, external IP, and OS image of each node.
Verification: Verify node details including IPs and OS images using kubectl get nodes -o wide
.
5. List all persistent volumes with labels:
kubectl get pv --show-labels
This command lists all persistent volumes along with their associated labels, providing metadata that helps in categorizing and managing storage resources.
Verification: Ensure the labels are correctly displayed using kubectl get pv --show-labels
.
6. List all deployments sorted by creation timestamp:
kubectl get deployments --sort-by=.metadata.creationTimestamp
This command lists all deployments in the current namespace sorted by their creation timestamp, allowing for chronological management of deployments.
Verification: Confirm the sorted order matches the expected creation timeline using kubectl get deployments --sort-by=.metadata.creationTimestamp
.
7. List all namespaces:
kubectl get namespaces
This command lists all namespaces in the Kubernetes cluster. It’s useful for understanding the organizational structure of resources.
Verification: Ensure all namespaces are listed correctly using kubectl get namespaces
.
8. List all configmaps with detailed information:
kubectl get configmaps -o json
This command retrieves detailed information about all configmaps in JSON format, including data stored within each configmap.
Verification: Check the JSON output for each configmap using kubectl get configmaps -o json
.
9. List all endpoints for services:
kubectl get endpoints
This command lists all endpoints associated with services, providing information about where the service is exposed and what pods serve the service.
Verification: Review the list of endpoints and associated pods using kubectl get endpoints
.
10. List all events across the cluster:
kubectl get events --all-namespaces
By specifying --all-namespaces
, this command fetches all events from all namespaces, helping in monitoring cluster-wide activities and issues.
Verification: Monitor and investigate cluster events using kubectl get events --all-namespaces
.
Also check similar articles.
Understanding Kubernetes Resources with kubectl explain
Setting Features on Kubernetes Objects using kubectl set
Running Docker Images on Kubernetes with kubectl run
Expose Kubernetes Services Easily with kubectl expose
How to Create Kubernetes Resources from Files or Stdin
Discussion about this post