---
slug: "kubernetes-ingress-cannot-get-remote-real-ip-adress-resolved"
title: "How We Managed to Retrieve Remote IP Addresses via Kubernetes Ingress"
description: "I attempted to retrieve the source global IP address from HTTP requests through Kubernetes Ingress, but I ended up obtaining the IP address of Kubernetes' local network, which did not work as intended.\n\nAfter switching Kubernetes to MicroK8s and using its built-in Ingress controller, I was able to successfully retrieve the global remote IP address. This is a note on that experience."
url: "https://www.ytyng.com/en/blog/kubernetes-ingress-cannot-get-remote-real-ip-adress-resolved"
publish_date: "2022-06-19T14:42:52Z"
created: "2022-06-19T14:42:52Z"
updated: "2026-02-26T22:58:53.283Z"
categories: ["kubernetes"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/a34dfb3369c6464dbc90f485e3874081.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# How We Managed to Retrieve Remote IP Addresses via Kubernetes Ingress

<p>I tried to obtain the source global IP address from HTTP requests through Kubernetes Ingress, but I ended up getting the IP address of Kubernetes' local network, which wasn't successful.</p>
<p>By switching Kubernetes to microk8s and using the built-in ingress controller, I was able to obtain the global remote IP address. Here are the notes.</p>
<p>The OS of the node is Ubuntu 20.04</p>
<h2>1. Unsuccessful Attempt</h2>
<p>In 2021.<br />The LAN is 192.168.0.0/24, and both the Kubernetes nodes and the requesting PC have IP addresses of 192.168.0.X.</p>
<p><br />I started Rancher with Docker, and in the built-in k3s cluster, I deployed the following:</p>
<pre>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/baremetal/deploy.yaml</pre>
<p>This set up the ingress controller.</p>
<p>When I started an nginx pod and made a request through Ingress, checking the access logs showed:</p>
<pre>X-Real-IP: 10.42.0.1<br />X-Forwarded-For: 10.42.0.1</pre>
<p>This was the IP address of the gateway within Kubernetes.</p>
<p>I wanted this to be the original IP address of the requesting PC, but I couldn't find any useful information to achieve that.</p>
<h2>2. Successful Attempt</h2>
<p>In 2022.</p>
<p>I discarded the above Kubernetes cluster and created a new MicroK8s cluster.</p>
<pre>sudo snap install microk8s --classic</pre>
<p>Enabled the Ingress controller</p>
<pre>microk8s enable dns ingress</pre>
<p>With the Ingress manifest and other configurations the same as in step 1, when I made a request, the logs showed:</p>
<pre>X-Real-IP: 192.168.0.159<br />X-Forwarded-For: 192.168.0.159</pre>
<p>This correctly obtained the client's IP address.</p>
