Skip to content

Ingress resource creation with kubectl

Ingress is an API object that manages external access to services in a cluster, typically via HTTP.^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md] It functions as a unified entry point, providing capabilities such as load balancing, SSL termination, and name-based virtual hosting.^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]

Prerequisites

Before creating an Ingress resource, an Ingress Controller (such as Nginx) must be running in the cluster.^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md] Additionally, a standard Deployment and Service should exist to serve as the target for the traffic.

Creating a Deployment and Service

First, deploy a simple application (e.g., Apache HTTPD) and expose it via a Service:^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]

kubectl create deployment demo --image=httpd --port=80
kubectl expose deployment demo

Creating the Ingress Resource

Once the application is running, create an Ingress resource to route traffic. The following command creates an Ingress that maps the host demo.localdev.me to the demo service on port 80:^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]

kubectl create ingress demo-localhost --class=nginx \
  --rule=demo.localdev.me/*=demo:80

Verification via Port Forwarding

To verify the configuration immediately without an external LoadBalancer, you can use kubectl port-forward. This forwards local traffic to the Ingress Controller service:^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]

kubectl port-forward --namespace=ingress-nginx service/ingress-nginx-controller 8080:80

With the port forward active, accessing http://demo.localdev.me:8080/ should route the traffic through the Ingress to the backend demo service.^[400-devops__06-Kubernetes__k8s-learning__06.ingress__README.md]

Sources