Ingress for External Access
Configure Ingress to manage external access to services, offering HTTP/S routing and load balancing.
Ingress for External Access is a free DevOps Bootcamp lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond NodePort & LoadBalancer
We've explored different Kubernetes Service types like NodePort and LoadBalancer for exposing applications externally.
While useful, these can become cumbersome for managing complex external access requirements, especially when you need to host many applications or APIs on a single IP address with specific routing rules.
This is where Ingress comes into play, offering a more powerful and flexible solution.
Introducing Kubernetes Ingress
Ingress is a Kubernetes API object that manages external access to the services in a cluster, primarily for HTTP and HTTPS traffic.
- It acts as a single entry point for external requests.
- It enables HTTP/S routing based on hostnames or URL paths.
- It can also provide features like SSL/TLS termination and load balancing.
Think of Ingress as a smart traffic controller that directs web traffic to the correct internal Services.
The Ingress Controller
An Ingress resource itself is just a set of rules; it doesn't handle traffic directly. To make Ingress functional, you need an Ingress Controller running in your cluster.
The Ingress Controller watches for Ingress resources and configures an external load balancer (or reverse proxy) according to the defined rules.
Popular Ingress Controllers include Nginx, Traefik, and cloud-specific ones like GCE Ingress for Google Cloud or AWS Load Balancer Controller.
How Ingress Rules Work
Ingress defines rules that map incoming external requests to specific backend Services within your cluster. These rules typically specify:
- Host: The domain name (e.g.,
www.my-app.com). - Path: The URL path (e.g.,
/api,/blog). - Backend Service: The Kubernetes Service and port to which traffic should be forwarded.
The Ingress Controller evaluates these rules for every incoming request to determine the correct destination.
Crafting an Ingress YAML
Like other Kubernetes resources, Ingress is defined using a YAML manifest. Here's a basic structure illustrating the key fields:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-web-service
port:
number: 80Simple Path-Based Ingress
Let's create an Ingress resource that routes all traffic for the root path (/) of myapp.example.com to a Service named my-web-service on port 80.
Ensure you have a Deployment and Service named my-web-service running in your cluster before applying this Ingress.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: basic-app-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-web-service
port:
number: 80Deploying Your Ingress
To deploy your Ingress resource, save the YAML to a file (e.g., basic-ingress.yaml) and use kubectl apply:
kubectl apply -f basic-ingress.yaml
You can check the status of your Ingress with kubectl get ingress. The Ingress Controller will then configure the external load balancer based on these rules.
To test, you'll typically need to update your local /etc/hosts file (or DNS) to point myapp.example.com to the external IP address of your Ingress Controller.
Host-Based Routing Example
Ingress is perfect for hosting multiple applications on a single external IP address by using different hostnames. Here, app1.example.com routes to service-app1, and app2.example.com routes to service-app2.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: host-routing-ingress
spec:
rules:
- host: app1.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-app1
port:
number: 80
- host: app2.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-app2
port:
number: 80Multiple Paths, One Host
You can also route different URL paths on the same hostname to different backend services. This is ideal for microservices architectures or different sections of a single application.
For example, requests to api.example.com/users go to users-service, while requests to api.example.com/products go to products-service.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: path-routing-ingress
spec:
rules:
- host: api.example.com
http:
paths:
- path: /users
pathType: Prefix
backend:
service:
name: users-service
port:
number: 80
- path: /products
pathType: Prefix
backend:
service:
name: products-service
port:
number: 80Ingress Purpose Check
Which of the following are primary benefits of using Kubernetes Ingress?
Recap: Ingress for Smart Routing
Great job! You've learned about Kubernetes Ingress, a crucial component for managing how external users interact with your applications.
- Ingress provides flexible HTTP/S routing based on hostnames and URL paths.
- It requires an Ingress Controller (like Nginx) to observe Ingress rules and configure routing.
- It simplifies exposing multiple services through a single external IP address, making your cluster more efficient and manageable.
Mastering Ingress is key to building robust and accessible cloud-native applications!
Frequently asked questions
Is the “Ingress for External Access” lesson free?
Yes — the full text of “Ingress for External Access” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Ingress for External Access”?
Configure Ingress to manage external access to services, offering HTTP/S routing and load balancing. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Ingress for External Access” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Exposing Apps with Services
- Service Types: ClusterIP, NodePort, LoadBalancer
- Ingress for External Access
- DNS and Service Discovery