How to filter resources by namespace?

0167

To filter resources by namespace in Kubernetes, you can use the -n or --namespace flag with the kubectl command. Here are some examples:

  1. Get all resources in a specific namespace:

    kubectl get all -n <namespace-name>
    
  2. Get Pods in a specific namespace:

    kubectl get pods -n <namespace-name>
    
  3. Get Deployments in a specific namespace:

    kubectl get deployments -n <namespace-name>
    
  4. Get Services in a specific namespace:

    kubectl get services -n <namespace-name>
    

Replace <namespace-name> with the name of the namespace you want to filter by.

If you want to set a default namespace for all subsequent commands, you can use:

kubectl config set-context --current --namespace=<namespace-name>

This way, you won't need to specify the namespace for each command. Let me know if you need further assistance!

0 Comments

no data
Be the first to share your comment!