liveBook · Manning

Loopback interface

As explained in Kubernetes in Action, Second Edition

A loopback device is a network interface that routes traffic within the same host or network namespace without sending it through an external network.

A loopback interface routes traffic within the same host or network namespace instead of sending it through an external network. The local address is commonly called localhost. section 5.3.1

In a pod, kubectl port-forward ultimately reaches the container through the pod’s loopback device. The application must listen on that interface; listening only on the pod’s eth0 interface prevents port forwarding from reaching it. section 5.3.1

Accessing a pod through localhost

Run kubectl port-forward kiada 8080, then curl localhost:8080. The local curl request travels through the port-forward proxy and reaches the application through the pod’s loopback device. section 5.3.1

$ kubectl port-forward kiada 8080
... Forwarding from 127.0.0.1:8080 -> 8080
... Forwarding from [::1]:8080 -> 8080

Shows kubectl port-forward binding local IPv4 and IPv6 loopback addresses to the pod’s application port. section 5.3.1

$ curl localhost:8080
Kiada version 0.1. Request processed by "kiada". Client IP: ::ffff:127.0.0.1

Shows localhost reaching the forwarded application and returning an HTTP response. section 5.3.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains the communication path and binding requirement, but stops short of implementing loopback networking internally.
Examples
Demonstrates kubectl port-forward kiada 8080 followed by curl localhost:8080.
What it assumes
Assumes familiarity with pods, containers, application ports, and kubectl port-forward.
What you can do after
Operate kubectl port-forward and diagnose failures caused by applications listening only on eth0.
How it connects
Connects loopback interfaces with localhost, pods, containers, Kubelet, kubectl port-forward, and network interfaces.

Also explained in

Compare how 2 books explain loopback interface →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.