<p>I'd like to ask how to count all pods in namespaces by namespaces' label value.</p>
<p>The structure is:</p>
<ul>
<li>namespace has 'teamName' label to specify a team the ns belongs to</li>
<li>pod has 'teamName' label to specify a team within the team the pod belongs to</li>
</ul>
<p>I'd like to count all pods over all namespaces which are belongs to ns.teamName.</p>
<p>I do have selection box (multi) for the ns.teamName <code>label_values(kube_namespace_labels, teamName)</code> - stored in <code>nsTeamName</code>.</p>
<p>I'm able to chose nsTeamName and for each namespace view the number of the pods <code>count by (namespace) (kube_pod_info * on (namespace) group_left() kube_namespace_labels{teamName=~&quot;$nsTeamName&quot;})</code>.</p>
<p>But what I'm not able to figure out how to count all pods in all namespaces with selected <code>nsTeamName</code>.</p>
<p>Thanks for help</p>

Pat
<p>I found a solution: <code>count by (teamName) (kube_pod_labels * on(namespace) group_left(teamName) kube_namespace_labels{teamName=~&quot;$nsTeamName&quot;})</code>.</p>
<p>The <code>group_left(teamName)</code> copies the label's value from namespace to pod label. After that counting over <code>teamName</code> works correctly.</p>
<p>If there's a better solution, please add it. Thanks</p>
