<p>I want to deploy kafka on kubernetes.</p>

<p>Because I will be streaming with high bandwidth from the internet to kafka I want to use the hostport and advertise the hosts "dnsName:hostPort" to zookeeper so that all traffic goes directly to the kafka broker (as opposed to using nodeport and a loadbalancer where traffic hits some random node which redirects it creating unnecessary traffic).</p>

<p>I have setup my kubernetes cluster on amazon. With <code>kubectl describe node ${nodeId}</code> I get the internalIp, externalIp, internal and external Dns name of the node. </p>

<p>I want to pass the externalDns name to the kafka broker so that it can use it as advertise host.</p>

<p>How can I pass that information to the container? Ideally I could do this from the deployment yaml but I'm also open to other solutions.</p>

<blockquote>
  <p>How can I pass that information to the container? Ideally I could do this from the deployment yaml but I'm also open to other solutions.</p>
</blockquote>

<p>The first thing I would try is <code>envFrom: fieldRef:</code> and see if it will let you reach into the <code>PodSpec</code>'s <code>status:</code> field to grab the <code>nodeName</code>. I deeply appreciate that isn't the <code>ExternalDnsName</code> you asked about, but if <code>fieldRef</code> works, it could be a lot less typing and thus could be a good tradeoff.</p>

<p>But, with "I'm also open to other solutions" in mind: don't forget that -- unless instructed otherwise -- each Pod is able to interact with the kubernetes API, and with the correct RBAC permissions it can request the very information you're seeking. You can do that either as a <code>command:</code> override, to do setup work before launching the kafka broker, or you can do that work in an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init container</a>, write the external address into a shared bit of filesystem (with <code>volume: emptyDir: {}</code> or similar), and then any glue code for slurping that value into your kafka broker.</p>

<p>I am 100% certain that the <code>envFrom: fieldRef:</code> construct that I mentioned earlier can acquire the <code>metadata.name</code> and <code>metadata.namespace</code> of the Pod, at which point the Pod can ask the kubernetes API for its own <code>PodSpec</code>, extract the <code>nodeName</code> from the aforementioned <code>status:</code> field, then ask the kubernetes API for the Node info, and voilà, you have all the information kubernetes knows about that Node.</p>
