<p>I've an ASP.NET Core Web API deployed on kubernetes via DevOps.
I have 4 pods.</p>
<p>Now, inside my API, I have a method that clear zentity framework plus cache, but when I call it using postman it is executed obviously only on called pod.</p>
<p>I'd like that when I call clear cache API on a pod, it collect all pods ip and recall clear cache API on every pod.</p>
<p>Can I collect pods ip inside the API ?</p>
<p>Thanks</p>

user3930528
<p>You can retrieve the Pods' IP addresses by using the official k8s C# client. You will also need relevant <code>Role</code>, <code>RoleBinding</code> and <code>ServiceAccount</code> to access the cluster's kube-apiserver.</p>
<pre class="lang-cs prettyprint-override"><code>using k8s;

namespace simple
{
    internal class PodList
    {
        private static void Main(string[] args)
        {
            // Load from the default kubeconfig on the machine (for local testing).
            var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();

            // Load from in-cluster configuration (for production)
            // var config = KubernetesClientConfiguration.InClusterConfig()

            IKubernetes client = new Kubernetes(config);
            
            var selector = &quot;app=abc&quot;;
            var list = client.CoreV1.ListNamespacedPod(&quot;default&quot;, labelSelector: selector, pretty: true);
            foreach (var item in list.Items)
            {
                Console.WriteLine(item.Status.PodIP);
            }
           
        }
    }
}
</code></pre>
<p>Check out these links:</p>
<ul>
<li><a href="https://github.com/kubernetes-client/csharp" rel="nofollow noreferrer">C# SDK for k8s</a></li>
<li><a href="https://github.com/kubernetes-client/csharp" rel="nofollow noreferrer">RBAC Authorizations</a></li>
<li><a href="https://github.com/kubernetes-client/csharp/blob/master/examples/simple/PodList.cs" rel="nofollow noreferrer">Example</a></li>
</ul>
