The kubectl get command shows what’s going on in a Kubernetes cluster. You can check the status of your resources safely, without risking any accidental changes.
Learn how to use kubectl get, one of the most common Kubernetes commands, through a set of practical examples.

What Is kubectl get Command
kubectl get is a Kubernetes command for retrieving details about resources in a cluster.
Developers and sysadmins use kubectl get to keep an eye on Kubernetes resources, check their status, and troubleshoot issues.
You can use kubectl get to:
- List pods, deployments, services, and other resources in your cluster.
- Check if a Pod is pending, running, or failing.
- See how many replicas are available and the status of deployments.
- Pinpoint resources that are not running as expected and then fix them.
- Filter results and customize how the information is displayed using flags.
Note: If you use Infrastructure as Code to manage your Kubernetes deployments, you can use kubectl get to check if the resources in your cluster match what you defined in the configuration.
kubectl get vs kubectl describe
These two commands differ in how much detail they provide. Usually, you start with the kubectl get command to find a resource that might have a problem. After that, you use kubectl describe to investigate the issue more closely.
Here are the key differences:
| kubectl get | kubectl create | |
|---|---|---|
| Resource status | Lists resources and shows their basic status. | Gives detailed information about a specific resource. |
| Output | Displays info in a compact table by default. | Shows detailed information in a human-readable format. |
| Event tracking | Does not show events by default. | Shows related Kubernetes events. |
| Use to | Quickly check what is running in a cluster. | Investigate resource settings, errors, or unexpected behavior. |
Note: If you do not have a Kubernetes cluster yet, check out our guide. It explains several ways to create one, depending on your project's needs and where you plan to deploy.
kubectl get Command Syntax
The kubectl get command uses a simple syntax:
kubectl get resource_type [resource_name] [flags]
Each part of the command has a specific role:
kubectl get. Retrieves information about Kubernetes resources.resource_type. This parameter is required. It tells Kubernetes which resource you want to retrieve, such as a pod, namespace, or deployment.[resource_name]. This optional parameter lets you specify a resource by name. If you leave it out, Kubernetes is going to list all the resources from the scope of the resource type you chose.[flags]. Flags are also optional. They change how the command works, like filtering results or changing the output format.
Note: If you find a pod you no longer need while using kubectl get, learn how to safely delete Kubernetes pods from your cluster.
kubectl get Options and Flags
The kubectl get command has several flags that let you filter results and change the output format. The following table lists the most common ones:
| Flag | Description |
|---|---|
-n | Lists resources from a specific Kubernetes namespace instead of the current one. |
-A | Lists resources across all namespaces in the entire cluster. |
-o | Changes how information is displayed. For example, you can show additional details or use JSON or YAML output formats. |
-l | Filters resources based on their Kubernetes labels. |
-w | Monitors resources and displays changes in the terminal in real time. |
--field-selector | Filters resources based on specific fields, such as their name or status. |
--sort-by | Sorts resources based on a specific field, such as their name or creation date. |
--show-labels | Adds a column showing the labels assigned to each resource. |
--ignore-not-found | Prevents the command from reporting an error if a requested resource does not exist. |
Note: If you are setting up a Kubernetes application and notice a required namespace is missing, you can create it directly from the command line with kubectl create.
kubectl get Command Examples
To try the following examples, you need:
- A Kubernetes cluster that is up and running.
- kubectl installed on your computer.
- Permission to view resources in the cluster.
Retrieving Pods and Basic Resource Lists
One of the most common kubectl get tasks you are likely to perform is checking if the pods in your cluster are running. Enter the following command to list the pods in the current namespace:
kubectl get pods
Kubernetes displays the pod names, how many containers are ready, their status, restart counts, and age. Based on this information, you can see whether any of the pods are having problems.

If you need more details about each pod, add the -o wide flag to your command:
kubectl get pods -o wide
Now, in addition to the previous data, you also get the pod's IP address and the name of the node it is running on.

To zero in on a specific pod, you can include its name from the list in the command. For example:
kubectl get pod frontend-857c9b9b8f-jj28v

The pod name above is just an example. Replace it with the name of the pod you want to check.
Inspecting Services, Deployments, and ReplicaSets
Kubernetes services give pods a stable network address and route traffic to them. To see the services in your current namespace, run this command:
kubectl get services
The output shows each service's name, IP address, and the port numbers it exposes.

The same syntax applies when you need to check deployments:
kubectl get deployment
Kubernetes shows how many replicas in each deployment are ready, up to date, and available.

You can also check the ReplicaSets, which control whether the correct number of pods is running:
kubectl get replicasets

You can check each resource separately, as shown above, or you can retrieve several resource types at once. Use the following command to view all three resource types instead of entering three different commands:
kubectl get services,deployments,replicasets

The resources will appear in the order you entered them in the command. This approach is useful if, for example, you need to review all the resources associated with an application in one go.
Querying Specific Namespaces and Cluster-Wide Resources
By default, kubectl get lists resources from the current namespace. If your apps run in more than one namespace, you can add the -n flag to select a specific one.
For example, this command shows all the pods in the production namespace:
kubectl get pods -n production
There are only four pods in the production namespace.

When you need to check pods across all namespaces in the cluster, use the -A flag:
kubectl get pods -A
You now get an additional column in the output table that shows which namespace each pod belongs to.

If you are not sure which namespaces exist, you can list them using the following command:
kubectl get namespaces

The output includes the namespace name, whether it's active or not, and how long it has been running.
Extracting Custom Output Formats with JSONPath and Custom Columns
If the output contains lots of details you don't actually need, use the -o flag to change how the information is displayed and pick which details you do want to see.
For example, you can use the following command to retrieve detailed pod information in JSON format:
kubectl get pods -o json
The output can be quite long and hard to read in the terminal. A better option would be to save the output to a file and review it later, or, even better, forward the JSON data to an application that checks and validates it.

JSONPath expressions are useful for extracting specific data from the output. For example, use the following command to show the names of the pods in your current namespace:
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
The pod names are shown in plain text separated by spaces, and not in the usual table format.

This isn't always ideal, especially if you are reviewing the data manually. You can use the custom-columns output format to get a more traditional table structure:
kubectl get pods -o custom-columns='NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName'

The command creates a table with three columns: the pod name, status, and assigned node.
Watching Resource Status Changes in Real Time
Kubernetes resources change their status all the time as applications start, stop, or restart. Instead of running kubectl get every single time, you can add the -w flag to watch for changes in the terminal as they happen. Here's how:
kubectl get pods -w
Kubernetes will show the current list of pods and keep watching for updates. If a pod's status changes, such as moving from Pending to Running, you'll see the change in the terminal immediately.

You can also combine flags to watch specific resources. For example, to watch pods in the production namespace, run:
kubectl get pods -n production -w
When you are ready, press Ctrl+C to stop watching and go back to the command prompt.
Inspecting Nodes on phoenixNAP Bare Metal Cloud Server Deployments
If you deployed a Kubernetes cluster on several physical servers, you can use kubectl get to check the nodes and see which workloads are running on them.
Note: If you are still deciding where to run your Kubernetes cluster, you can deploy one on phoenixNAP Bare Metal Cloud in minutes using its SUSE Rancher integration.
To see which nodes are registered with your Kubernetes cluster, enter:
kubectl get nodes
Kubernetes shows each node's name, status, role, age, and version. The STATUS column helps you spot which nodes are ready to run workloads and which may have issues.

Use the following command to get even more details about the nodes, like their internal IP and the operating systems they use:
kubectl get nodes -o wide

You can also find out which nodes are hosting your pods by listing pods across all namespaces:
kubectl get pods -A -o wide
This helps you track how workloads are distributed across your servers and know which nodes to check if an application stops working.
Common Problems When Using kubectl get Command
This section shows how to solve the most common problems you might face when using kubectl get.
"No resources found" and Namespace Mismatches
If you get the No resources found in namespace message after running kubectl get, you might be looking in the wrong namespace, or the resource may not exist.

To check if the resource, for example, a service, exists in another namespace, you can search the entire cluster:
kubectl get services -A
The second column lists the service names, while the first column shows which namespace each service belongs to.

Once you find the correct namespace, try the command again and specify that namespace:
kubectl get services -n production
It's also possible, although less likely, that you are connected to the wrong cluster. This might explain why you cannot find the resources you are looking for. Use the following command to check your current context:
kubectl config current-context

The output shows the context name, so you can see which cluster you are working with. If it's not the right one, switch to the correct cluster before running kubectl get again.
Handling Large Output Volumes
kubectl get output is organized in a clear table, but it can still be hard to review in the terminal if your cluster has lots of resources. Using different flags to narrow down the results often makes things easier to understand.
If you know which application you are looking for, you can use the -l flag to filter resources based on their Kubernetes label. For example:
kubectl get pods -l app=nginx
This command lists only the pods with the app=nginx label in the current namespace.

Another option is to use --field-selector to find resources based on specific fields, like their status. For instance, the following command only shows Pending pods:
kubectl get pods --field-selector=status.phase=Pending
If your main concern is how the data is organized rather than the amount of detail, you can use the --sort-by flag to sort pods based on when they were created:
kubectl get pods --sort-by=metadata.creationTimestamp

The results are sorted by the AGE column so that the oldest pod appears first.
Syntax Errors with Complex Output Selectors
You can customize kubectl get output using different flags and expressions. Some expressions are quite long and include lots of special characters, so it's easy to make mistakes.
For example, the following JSONPath expression is missing a closing curly brace:
kubectl get pods -o jsonpath='{itmes[*].metadata.name'

In this example, the unclosed action message means that the expression is incomplete. To fix it, just add the missing curly brace (}) at the end.
The same applies when you use the custom-columns output format to choose which columns should appear in the table. Make sure each column has a name and the correct field path. For example, the following command has a typo:
kubectl get pods -o custom-columns='NAME:.emtadata.name,STATUS:.status.phase'
This command will run without errors, but the NAME column will show <none> instead of the pod names.

Correct the field path to solve the problem:
kubectl get pods -o custom-columns='NAME:.metadata.name,STATUS:.status.phase'
Also, remember that quotation marks work differently depending on your shell. For example, Linux shells usually use single quotes around JSONPath expressions, while Windows Command Prompt uses double quotes.
Best Practices When Using kubectl get Command
Follow these best practices to get the most out of the kubectl get command:
- You do not have to search the entire cluster every time. If you know what you are looking for, use the
-nflag to search within a specific namespace, or the-lflag to target a specific app by its Kubernetes label. - Try different output formats to see which one works best for you. The default table is easy to read, but if you are passing data to a script, you should use the
-o jsonor-o yamloptions to get output that's easier for programs to process. - If you want to watch the status of your pods during an app deployment, use the
-wflag. This lets you see how resources change in real time, so you do not have to keep running the same terminal command over and over. - When troubleshooting, start with the
kubectl getcommand to find the affected resources. If you need more information, you can use thekubectl describecommand to investigate further. - If you use
kubectl getin a script, consider using the--ignore-not-foundflag. This way, if a resource is missing, Kubernetes will not show errors, so your workflows are less likely to be interrupted. - The
kubectl getcommand can access Kubernetes Secrets, so it's important to follow Kubernetes RBAC best practices to control who can see them. Make sure you do not show secrets in the terminal or export them, as they may end up in terminal recordings or logs.
Conclusion
You can now track cluster resources and monitor their status. The kubectl get command is also very useful when you need to troubleshoot issues in your cluster.
As your cluster grows, it can be difficult to review output from the command line. You might want to try an open-source Kubernetes monitoring tool. These tools make it easier to monitor resources in a visual dashboard.



