kubectl Verified current stable Not installed? Kubernetes

Kubectl / Get Deployments In Namespace

Get Deployments In Namespace

Use kubectl to retrieve all deployments in a specified Kubernetes namespace for troubleshooting.

$
Terminal
kubectl get deploy -n <namespace>

When To Use

Identifying discrepancies in deployments during a troubleshooting session.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
kubectl get deploy -n <namespace>

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
NAME                READY   UP-TO-DATE   AVAILABLE   AGE
my-deployment       3/3     3            3           10d
another-deployment  2/2     2            2           5d

Power User Variants

Optimized versions

kubectl get deploy -n <namespace>

Shortened version using 'deploy'.

kubectl get deployments --namespace=<namespace>

Using the long form for namespace.

Unix Pipeline

Shell combinations

kubectl get deployments -n <namespace> -o wide

Get deployments with additional details.

kubectl get deployments -n <namespace> -l app=myapp

Filter deployments by label.

Troubleshooting

Common pitfalls

Error from server (NotFound): namespaces "namespace" not found

Solution: Ensure the namespace exists and is correctly spelled.

Error: the server doesn't have a resource type "deployments"

Solution: Check if the correct resource type is specified.

Command Breakdown

What each part is doing

kubectl
Base Command
The executable that performs this operation. Here it runs Kubectl before the shell applies any redirect operators.
deploy
deploy|deployments
The value supplied for deploy|deployments.
-n
n| namespace
The value supplied for n| namespace.
<namespace>
namespace
The value supplied for namespace.
-n
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Open your terminal.

  2. Step 2

    Run the command: kubectl get deployments -n <namespace>

  3. Step 3

    Review the list of deployments returned.

Alternative Approaches

Comparable commands in other tools

Alternative kubernetes tools for the same job.