<p>I have a set of pods providing nsqlookupd service.
Now I need each nsqd container to have a list of nsqlookupd servers to connect to (while service will point to different every time) simultaneously. Something similar I get with </p>

<pre><code>kubectl describe service nsqlookupd
...
Endpoints: ....
</code></pre>

<p>but I want to have it in a variable within my deployment definition or somehow from within nsqd container</p>

<p>Sounds like you would need an extra service running either in your <code>nsqd</code> container or in a separate container in the same pod. The role of that service would be to pole the API regularly in order to fetch the list of endpoints.</p>

<p>Assuming that you enabled <a href="http://kubernetes.io/docs/user-guide/service-accounts/" rel="noreferrer">Service Accounts</a> (enabled by default), here is a proof of concept on the shell using <code>curl</code> and <code>jq</code> from inside a pod:</p>

<pre class="lang-bash prettyprint-override"><code># Read token and CA cert from Service Account
CACERT="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)

# Replace the namespace ("kube-system") and service name ("kube-dns")
ENDPOINTS=$(curl -s --cacert "$CACERT" -H "Authorization: Bearer $TOKEN" \
    https://kubernetes.default.svc/api/v1/namespaces/kube-system/endpoints/kube-dns \
)

# Filter the JSON output
echo "$ENDPOINTS" | jq -r .subsets[].addresses[].ip
# output:
#   10.100.42.3
#   10.100.67.3
</code></pre>

<p>Take a look at the source code of <a href="https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dns/kube2sky/kube2sky.go" rel="noreferrer">Kube2sky</a> for a good implementation of that kind of service in Go.</p>
