<p>I'm trying to use internal service DNS for service-to-service HTTP communication.</p>
<p>If I try to curl a pod from another deployment pod it is working but unable to use it in golang net/http service</p>
<pre><code>2023/01/27 15:48:37 oauth2.go:90: oauth2 url  http://hydra-admin.microservices.svc.cluster.local:4445/oauth2/auth/requests/login/accept
2023/01/27 15:48:37 oauth2.go:101: Unable to make http request  Put &quot;http://localhost:4445/admin/oauth2/auth/requests/login/accept?login_challenge=b569006c8b834a298cf1cd72e2424953&quot;: dial tcp [::1]:4445: connect: connection refused
</code></pre>
<p>hydra-admin.microservices.svc.cluster.local is resolved to localhost when the API call is made</p>
<p>but curl works as you see below</p>
<pre><code>/ # curl -X PUT http://hydra-admin:4445/admin/oauth2/auth/requests/login/accept?login_challenge=6f51146e49c54b739de8a37b25a72349
{&quot;error&quot;:&quot;invalid_request&quot;,&quot;error_description&quot;:&quot;The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Unable to decode body because: EOF&quot;}
</code></pre>
<p>What am I missing here?</p>

Hariharan Sivakumar
<p>Per my comment, depending on how you are building your <code>go</code> executable will have an effect on how it behaves within a <code>k8s</code> environment. Are you using a <code>scratch</code> image or a <code>CGO_ENABLED=1</code> image?</p>
<p>From the <code>dns</code> package <a href="https://pkg.go.dev/net#hdr-Name_Resolution" rel="nofollow noreferrer">docs</a> there's a caveat on DNS behavior</p>
<blockquote>
<p>By default the pure Go resolver is used, because a blocked DNS request
consumes only a goroutine, while a blocked C call consumes an
operating system thread. When cgo is available, the cgo-based resolver
is used instead under a variety of conditions:</p>
</blockquote>
<blockquote>
<p>... when /etc/resolv.conf or /etc/nsswitch.conf specify the use of features
that the Go resolver does not implement, <em><strong>and when the name being
looked up ends in .local</strong></em> or is an mDNS name.</p>
</blockquote>
<p>So I would suggest - to maximized your success rate for both external &amp; internal DNS requests - building your <code>go</code> executable for <code>k8s</code> like so:</p>
<pre><code>CGO_ENABLED=1 go build -tags netgo
</code></pre>
