<p>I have <a href="https://github.com/kubernetes-client/csharp/" rel="nofollow noreferrer">KubernetesClient</a> code running my app on K3s Orchestrator. I have created service <code>prog</code>, <code>prog-external</code> &amp; <code>my-module</code> with specified Ports for <code>app-module</code> namespace which are now seen in <strong><code>kubectl get svc -A</code></strong> command:</p>
<pre><code>root@Ubuntu20-VM:~# kubectl get svc -A
NAMESPACE      NAME              TYPE           CLUSTER-IP     PORT(S)                         AGE
default        kubernetes        ClusterIP      10.43.0.1      443/TCP                         86m
kube-system    kube-dns          ClusterIP      10.43.0.10     53/UDP,53/TCP,9153/TCP          86m
kube-system    metrics-server    ClusterIP      10.43.4.133    443/TCP                         86m
app-module     prog              ClusterIP      10.43.175.255  9008/TCP,9009/UDP,9001/TCP      64m
app-module     prog-external     NodePort       10.43.108.249  9000:30001/TCP,9001:30002/TCP   64m
app-module     my-module         ClusterIP      10.43.23.30    9008/TCP,9009/UDP,9001/TCP      64m
</code></pre>
<p>Can someone please let me know that if there is any API in <a href="https://github.com/kubernetes-client/csharp/" rel="nofollow noreferrer">KubernetesClient</a> to find/get theses services ? Please suggest.</p>
<p><strong>PS:</strong> I think API <a href="https://raw.githubusercontent.com/kubernetes-client/csharp/463e2d94dfe5a4bb54372aaab957ca8d794d767e/src/KubernetesClient/generated/Kubernetes.cs" rel="nofollow noreferrer">ListNamespacedServiceWithHttpMessagesAsync</a> will return all pods config for namespace <code>app-module</code> , <strong>but</strong> I only want those pods config in <code>app-module</code> NS for which I <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-services/#accessing-services-running-on-the-cluster" rel="nofollow noreferrer">created services</a> , here which are : <code>prog</code>, <code>prog-external</code> &amp; <code>my-module</code>. Please correct me if my understanding is wrong ?</p>

Thor
<p>You cannot fetch all pods related to services (in the namespace) with one Kubernetes API call (one function call in Kubernetes C# library).</p>
<hr />
<p>You need to do the following:</p>
<ol>
<li>List all Services (filtered by namespace/name)</li>
<li>List all Endpoints / Endpoint Slices (related to services you fetched in point 1.)</li>
<li>List all Pods (related to Endpoint / Endpoint Slices from point 2.)</li>
</ol>
<p>You can think of the service -&gt; pod like a one-way relation. So service points to pods (via endpoint), but pod does not know anything about the service</p>
<hr />
<p>A more Kubernetes-friendly way of achieving what you want would be to actually label your resources. So, keep a consistent labels across your services/pods, then you list your resources by labels.</p>
