<p>I have set these environment variables inside my pod named <strong>main_pod</strong>.</p>
<pre><code>$ env
HTTP_PROXY=http://myproxy.com
http_proxy=http://myproxy.com
</code></pre>
<p>I also have another dynamic pod in pattern <strong>sub_pod-{number}</strong> which has a service attached to it called <code>sub_pod-{number}</code>.</p>
<p>So, if I add <code>NO_PROXY=sub_pod-1</code> environment variable in <strong>main_pod</strong>, request with URL <code>http://sub_pod-1:5000/health_check</code> will run successfully as it won't be directed through proxy which is fine.</p>
<p>But I want this process to be dynamic. <code>sub_pod_45</code> might spawn at runtime and <code>sub_pod-1</code> might get destroyed. Is there any better way to handle this rather than updating <code>NO_PROXY</code> for every pod creation / destruction ?</p>
<p>Is there any resource / network policy / egress rule from which I can tell pod that if domain name belongs to kubernetes service, do not route it through proxy server?</p>
<p>Or can I simply use regex or glob patterns in <code>NO_PROXY</code> env variable like <code>NO_PROXY=sub_pod-*</code> ?</p>
<p>Edited</p>
<p><strong>Result of nslookup</strong></p>
<pre><code>root@tmp-shell:/# nslookup sub_pod-1
Server:     10.43.0.10
Address:    10.43.0.10#53

Name:   sub_pod-1.default.svc.cluster.local
Address: 10.43.22.139

</code></pre>
<h3>When <code>no_proxy=cluster.local</code>,</h3>
<p><strong>Proxy bypassed when requested with FQDN</strong></p>
<p><code>res = requests.get('http://sub_pod-1.default.svc.cluster.local:5000')</code></p>
<p><strong>Proxy didn't bypass when requested with service name only</strong></p>
<p><code>res = requests.get('http://sub_pod-1:5000')</code>  # I want this to work</p>
<p>I would not want to ask my developers to change the application to use FQDN.</p>
<p>Is there any way cluster can identify if URL resolves to a service present within the network and if it happens do not route the request to proxy ?</p>

Saurav Pathak
<p>Libraries that support the <code>http_proxy</code> environment variable generally also support a matching <code>no_proxy</code> that names things that shouldn't be proxied.  The exact syntax seems to <a href="https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/#no_proxy" rel="nofollow noreferrer">vary across languages and libraries</a> but it does seem to be universal that setting <code>no_proxy=example.com</code> causes <code>anything.example.com</code> to not be proxied either.</p>
<p>This is relevant because the <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#dns-records" rel="nofollow noreferrer">Kubernetes DNS system</a> creates its names in a domain based on the cluster name, by default <code>cluster.local</code>.  The canonical form of a Service DNS name, for example, is <code>service-name.namespace-name.svc.cluster.local.</code>, where <code>service-name</code> and <code>namespace-name</code> are the names of the corresponding Kubernetes objects.</p>
<p>I suspect this means it would work to do two things:</p>
<ol>
<li>Set an environment variable <code>no_proxy=cluster.local</code>; and</li>
<li>Make sure to use the FQDN form when calling other services, <code>service.namespace.svc.cluster.local</code>.</li>
</ol>
<p>Pods have similar naming, but are in a <code>pod.cluster.local</code> subdomain.  The <code>cluster.local</code> value is configurable at a cluster level and it may be different in your environment.</p>
