liveBook · Manning

Privileged port

As explained in Kubernetes for Developers

A privileged port is a network port below 1024 that traditionally requires elevated operating-system privileges for a process to bind to it.

A privileged port is a network port below 1024, such as HTTP port 80, that traditionally requires elevated operating-system privileges to bind. Running a container as a non-root user improves defense in depth, but an application listening on port 80 can then fail with a permission error. section 12.4

The practical workaround is to separate the application’s listening port from its external port. Configure the server to listen on an unprivileged port such as 8080, then configure a Kubernetes Service to expose port 80 and target port 8080.

Moving a non-root server off port 80

A Deployment enforcing runAsNonRoot can fail when its image still starts a server on port 80. Change the server to 8080 and set the Service’s targetPort to 8080; clients can continue using port 80.

How Kubernetes for Developers covers it

How deep it goes
Traces the failure from non-root enforcement through port-binding errors to an application and Service configuration fix.
Examples
Uses a Python HTTP server moved from port 80 to 8080 and a Kubernetes Service that preserves external port 80.
What it assumes
Assumes basic familiarity with containers and Kubernetes Deployments while demonstrating the relevant failure and configuration changes.
What you can do after
Apply non-root execution by moving the application to an unprivileged port and mapping the public port through a Service.
How it connects
Connects privileged ports with non-root containers, Docker, Kubernetes, securityContext, and Services.

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.