Can I set custom ports for a Kubernetes ingress to listen on besides 80 / 443?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In Kubernetes, the ingress resource is utilized to manage external access to services within a cluster, typically supporting HTTP and HTTPS traffic. By default, ingress controllers operate on well-known ports: 80 for HTTP and 443 for HTTPS. However, there might be scenarios where you wish to use custom ports. Below is a detailed exploration of how you can achieve this, along with potential limitations and examples.
Understanding Kubernetes Ingress
Kubernetes ingress provides HTTP and HTTPS routing to services based on defined rules. Typically, it is a collection of rules that permit the host and path-based routing to the services.
The typical usage involves ingress controllers that encapsulate specific functionalities, such as:
- Nginx Ingress Controller: Routes and manages external access to the services.
- Traefik, Istio, among others, with specialized capabilities.
By default, Kubernetes ingress relies on ports 80 and 443. But what if you need to manage traffic through different ports, such as 8080 or another custom port?
Configuring Custom Ports
Limitations
- Ingress Controller Dependency: Not all ingress controllers support custom ports. The ability to set a custom port is directly tied to the ingress controller being used.
- Protocol Constraints: Ingress is designed for HTTP-based traffic, so non-HTTP traffic needs alternative methods like using
NodePortorLoadBalancer.
Example with Nginx Ingress
By default, the Nginx Ingress Controller listens on two ports, 80 and 443. To override this behavior, consider the following configuration:
- Custom ConfigMap: Create a custom
ConfigMapdefining the port:
- Ingress Controller Deployment: Add the following environment variables to the
ingress-nginx-controllerdeployment or modify the default configuration for Nginx:
- Service Configuration: Ensure the Service exposing the Nginx controller is updated to accommodate custom ports. Here is an example for NodePort configuration.
Using Alternative Approaches
If the ingress controller doesn't support custom ports, you can consider using a LoadBalancer or NodePort type service to expose the service on a different port:
- NodePort: Exposes the service on each node's IP at a static port, defined by
nodePort. - LoadBalancer: Creates an external load balancer in supported cloud environments and assigns it a fixed external IP.
Summary Table of Key Points
| Aspect | Details |
| Default Ingress Ports | 80 (HTTP), 443 (HTTPS) |
| Customization Capability | Controller-dependent; not universally supported |
| Common Ingress Controllers | Nginx, Traefik, Istio |
| Custom Port Configuration | Modify ConfigMap and ingress controller deployment |
| Alternative Approaches | Use NodePort or LoadBalancer for custom ports |
Conclusion
Setting custom ports beyond 80 and 443 for Kubernetes ingress is indeed feasible, though it is subject to the capabilities of the ingress controller in use. It's crucial to understand the IaaS being employed and adjust the network policies and configurations in tandem. Custom configurations often involve changes to ConfigMap, service definitions, and the ingress controller deployments themselves. Always verify the documentation of the ingress controller for specific support and configurations to avoid accidental misconfigurations.
Related reading
- Can I use autocompletion for kubectl in zsh?
- Can I use local SSDs on GKE for fast, temporary storage within a pod?
- Can Kubernetes be used like Docker Compose?
- Can not delete pods in Kubernetes
- Can I set max_retries for requests.request?
- Can I somehow do a synchronous HTTP request via NSURLSession in Swift
- Can not override replicas of deployment k8s
- can two kubernetes volumes mount to the same place

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.