kubectl Verified current stable Not installed? Kubernetes

Kubectl / Check User Permission Specific Verb Resource

Check User Permission Specific Verb Resource

Use kubectl to verify if a user can perform a specific action on a Kubernetes resource.

$
Terminal
kubectl auth can-i <verb> <resource> -n <namespace>

When To Use

Determine if a user has permission for a specific action on a resource.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
kubectl auth can-i <verb> <resource> -n <namespace>

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
yes

Power User Variants

Optimized versions

kubectl auth can-i get pods

Check if the user can get pods.

kubectl auth can-i create deployments -n my-namespace

Check if the user can create deployments in a specific namespace.

Unix Pipeline

Shell combinations

kubectl auth can-i delete services -n my-namespace

Check if the user can delete services in a specific namespace.

Troubleshooting

Common pitfalls

Error from server: User "user" cannot "verb" "resource"

Solution: Check the user's role bindings and permissions.

Error: resource not found

Solution: Ensure the resource type is correct and exists in the cluster.

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.
<verb>
verb
The value supplied for verb.
<resource>
resource
The value supplied for resource.
-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

    Replace {{verb}} with the action you want to check (e.g., get, create).

  2. Step 2

    Replace {{resource}} with the Kubernetes resource type (e.g., pods, deployments).

  3. Step 3

    Optionally specify the namespace using -n or --namespace followed by the namespace name.

Alternative Approaches

Comparable commands in other tools

Alternative kubernetes tools for the same job.