Search code examples
kuberneteskubectl

What is relationship betweeen Node and Namespaces in kubernetes?


Relationship between cluster and namespaces : - Namespaces are in cluster Relationship between cluster and node :- Nodes are in cluster Relationship between pod and namespaces :- Pods run under namespace Relationship between pod and Node : - pods can run on node.

If I want relationship for node and pods , it can be obtained by command :- kubectl get pod -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName --all-namespaces

How to get relationship between node and namespace?


Solution

  • Your question isn't clear. But, lets try...

    There is no such relation (in terms of relation). Resources in namespaces can be located on different nodes.


    If your question about querying resources, use --field-selector option.

    kubectl get pods -all-namespaces \ 
     --field-selector=metadata.namespace!=default,spec.nodeName==minikube
    
    • or export information in json and filter with jq
    • or export information in text and filter with grep
    • or export in ... and filter with ...

    or you want to show namespace with node?

    kubectl get pod --all-namespaces \ 
       -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,NODE:.spec.nodeName