<p>I deployed a squid proxy in each namespace cause I want to access the services from external via the squid proxy, thus I need to add the line below to the squid.conf so that I can access services just using service names:</p>

<pre><code>append_domain .${namespace}.svc.cluster.local
</code></pre>

<p>Here is my problem:<br>
  I can get <code>${namespace}</code> via <code>metadata.namespace</code> inside a pod, but how can I get the cluster domain ? Is it possible ?<br>
I’ve tried this but it retruned an error when creating pod:</p>

<pre><code>  - name: POD_CLUSERDOMAIN
    valueFrom:
      fieldRef:
        fieldPath: metadata.clusterName
</code></pre>

<p>Thanks for your help.</p>

<p>Alright, failed to get the current <code>NAMESPACE</code> inside a pod, but I find another way to reach the point -- retrieve the whole host domain from <code>search domian</code> in <code>resolv.conf</code>.</p>

<p>Here's the detail:</p>

<ul>
<li>keep the Dockerfile unmodified</li>
<li><p>add a <code>command</code> item to deployment.yaml</p>

<pre><code>image: squid:3.5.20
command: ["/bin/sh","-c"]
args: [ "echo append_domain .$(awk -v s=search '{if($1 == s)print $2}' /etc/resolv.conf) &gt;&gt; /etc/squid/squid.conf; /usr/sbin/squid -N" ]
</code></pre></li>
</ul>

<p>This will add a line like <code>append_domain .default.svc.cluster.local</code> to the end of file <code>/etc/squid/squid.conf</code> then we can access the services from external via the squid proxy just using <code>service</code> name now.</p>
