<p>In a container running with host networking option it is possible to use a host network interface and its IP from the container and contact external network <em>from</em> this interface and IP. So if a host has several IPs configured, the container can choose which one it uses.</p>

<p>Can I have a similar setup with Kubernetes and let a container use an host IP ?</p>

<p>NB: I need the process to contact an external service <em>from</em> specific IPs, I dont necessarily need those IPs to be assigned to a container from an external view.</p>

<p><code>hostNetwork=true</code> in pod specification exposes host network to the pod, and container can access network interfaces:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: lookup
spec:
  hostNetwork: true
  containers:
    - name: lookup
      image: sbusso/lookup_ips:latest
      ports:
      - containerPort: 9000
</code></pre>

<p>To test it: <code>kubectl port-forward lookup 9000</code> and then go to <a href="http://127.0.0.1:9000/" rel="nofollow noreferrer">http://127.0.0.1:9000/</a> and get network interfaces details:</p>

<pre><code>lo
- 127.0.0.1/8
- ::1/128
eth0
- 10.0.2.15/24
- fe80::a00:27ff:fea1:6e61/64
eth1
- 192.168.99.101/24
- fe80::a00:27ff:fe77:d179/64
</code></pre>

<p>Note this option is not recommended in Kubernetes good practices: <a href="https://kubernetes.io/docs/concepts/configuration/overview/#services" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/overview/#services</a></p>
