<p>I currently have a service that looks like this:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: httpd
spec:
  ports:
    - port: 80
      targetPort: 80
      name: http
      protocol: TCP
    - port: 443
      targetPort: 443
      name: https
      protocol: TCP
  selector:
    app: httpd
  externalIPs:
    - 10.128.0.2  # VM's internal IP
</code></pre>

<p>I can receive traffic fine from the external IP bound to the VM, but all of the requests are received by the HTTP with the source IP <code>10.104.0.1</code>, which is most definitely an internal IP – even when I connect to the VM's external IP from outside the cluster.</p>

<p>How can I get the real source IP for the request without having to set up a load balancer or ingress?</p>

<p>If you only have exactly one pod, you can use <code>hostNetwork: true</code> to achieve this:</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: caddy
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: caddy
    spec:
      hostNetwork: true # &lt;---------
      containers:
      - name: caddy
        image: your_image
        env:
        - name: STATIC_BACKEND # example env in my custom image
          value: $(STATIC_SERVICE_HOST):80
</code></pre>

<p>Note that by doing this <strong>your pod will inherit the host's DNS resolver</strong> and not Kubernetes'. That means you can no longer resolve cluster services by DNS name. For example, in the example above you cannot access the <code>static</code> service at <a href="http://static" rel="nofollow noreferrer">http://static</a>. You still can access services by their cluster IP, which are injected by <a href="https://kubernetes.io/docs/concepts/services-networking/service/#environment-variables" rel="nofollow noreferrer">environment variables</a>.</p>
