<p>I have a Kubernetes <code>Pod</code> (controlled by a <code>DaemonSet</code>) that needs to communicate with a daemon that belongs to the Weave Net CNI plugin and serves HTTP at <code>localhost:6784</code>.</p>

<p>In order to communicate with this server from inside the pod, do I have to equip it with <code>hostnetwork: true</code>, or is there another (better) way to do this?</p>

<p>I'm asking because in general <code>hostnetwork: true</code> should  be avoided, plus it also makes it more complicated for the pod to reach the Kubernetes API (which it also needs to do).</p>

<p>Since no better way became apparent, I'm now running the pod with <code>hostNetwork: true</code>. Its container mounts the host's file <code>/etc/kubernetes/kubelet.conf</code>, and it parses and employs the Kubernetes server URL as follows: </p>

<pre><code>with open('/etc/kubernetes/kubelet.conf', 'r') as stream:
  config = yaml.safe_load(stream)
current_context = config['current-context']
context = next(context for context in config['contexts'] if context['name'] == current_context)
cluster = next(cluster for cluster in config['clusters'] if cluster['name'] == context['context']['cluster'])
server = cluster['cluster']['server']

k8s_configuration = kubernetes.client.Configuration()
k8s_configuration.host = server
k8s_configuration.ssl_ca_cert = '/run/secrets/kubernetes.io/serviceaccount/ca.crt'
k8s_configuration.api_key_prefix['authorization'] = 'Bearer'
with open('/run/secrets/kubernetes.io/serviceaccount/token', 'r') as stream:
  k8s_configuration.api_key["authorization"] = stream.read()
k8s_client = kubernetes.client.ApiClient(k8s_configuration)
</code></pre>

<p>I am not using <code>kubernetes.config.load_kube_config()</code> to do the parsing, because it wants further credentials, such as <code>/var/lib/kubelet/pki/kubelet-client-current.pem</code>, which are not (and in this context should not be) mounted.</p>
