kubectl get: Viewing Kubernetes Resources
The kubectl get command is one of the most fundamental and frequently used commands in Kubernetes. It allows you to fetch and display information about various resources in your cluster, such as Pods, Deployments, Services, Nodes, and more.
Basic kubectl get Commands
Get Nodes
Displays information about the worker nodes in your cluster.
kubectl get nodesGet Pods
Pods are the smallest deployable units in Kubernetes.
# Get pods in the current namespace
kubectl get pods
# Get pods across all namespaces
kubectl get pods --all-namespaces
# Get pods in a specific namespace
kubectl get pods -n <namespace>
# Example:
kubectl get pods -n uatGet Namespaces
Namespaces help organize resources within a Kubernetes cluster.
kubectl get namespacesGet Persistent Volumes (PVs)
Persistent Volumes are pieces of storage in the cluster that have been provisioned by an administrator or dynamically provisioned using Storage Classes.
kubectl get pvGet Persistent Volume Claims (PVCs)
Persistent Volume Claims are requests for storage by a user, consumed by pods.
# Get PVCs in the current namespace
kubectl get pvc
# Get PVCs across all namespaces
kubectl get pvc --all-namespaces
# Get PVCs in a specific namespace
kubectl get pvc -n <namespace>
# Example:
kubectl get pvc -n uatGet Deployments
Deployments manage a replicated set of pods, ensuring they are running and updated in a controlled manner.
# Get deployments in the current namespace
kubectl get deployments
# Get deployments across all namespaces
kubectl get deployments --all-namespaces
# Filtering deployments (e.g., using grep for partial names)
kubectl get deployments --all-namespaces | grep homepageCommon kubectl get Options
-o wide: Provides more detailed information, such as Node IP, Pod IP, and container images.kubectl get pods -n <namespace> -o wide-wor--watch: Watches for changes to the specified resources, continuously updating the output.kubectl get pods -n <namespace> --watch-lor--selector: Filters resources by labels.kubectl get pods -n <namespace> -l app=my-app,env=production-o yaml/-o json: Outputs the resource in YAML or JSON format, useful for programmatic processing or detailed inspection.kubectl get pod <pod-name> -n <namespace> -o yaml--show-labels: Displays the labels associated with each resource.kubectl get pods -n <namespace> --show-labels