ingress
Kubernetes Ingress Lab
This lab guides you through setting up Kubernetes Ingress for routing external traffic to internal services. We will deploy sample applications, install an Nginx Ingress controller, and configure host-based routing and TLS.
1. Prerequisites: Kubernetes Cluster
Ensure you have a running Kubernetes cluster. You can use Minikube, Docker Desktop's Kubernetes, or a cloud-managed cluster. For on-premises setups, projects like Tigera Calico for On-Premises Kubernetes (link from original document) can be helpful, but any conformant cluster will do.
2. Initial Cluster Inspection
List Nodes: Verify your nodes are ready.
kubectl get noList Namespaces: See the existing namespaces in your cluster.
kubectl get namespaces
3. Deploy Sample Applications (app1 & app2)
We'll create two simple Nginx applications, each in its own namespace, and expose them via ClusterIP services.
Create and Deploy
app1:kubectl create ns app1 # The following YAMLs deploy Nginx and expose it via a ClusterIP service named 'my-nginx-clusterip' kubectl apply -n app1 -f https://raw.githubusercontent.com/xxradar/kuberneteslearning/master/nginx-deployment.yaml kubectl apply -n app1 -f https://raw.githubusercontent.com/xxradar/kuberneteslearning/master/nginx-expose-clusterip.yamlCreate and Deploy
app2:kubectl create ns app2 kubectl apply -n app2 -f https://raw.githubusercontent.com/xxradar/kuberneteslearning/master/nginx-deployment.yaml kubectl apply -n app2 -f https://raw.githubusercontent.com/xxradar/kuberneteslearning/master/nginx-expose-clusterip.yamlTest
app1andapp2Internally: Verify that the applications are running and their services are up.kubectl get all -n app1 -o wide kubectl get all -n app2 -o wideTest connectivity to the services from within the cluster (e.g., using a temporary pod with
siegeorcurl):# Test app1's service (my-nginx-clusterip.app1.svc.cluster.local or just my-nginx-clusterip from within app1 ns) kubectl run siege-app1 -it -n app1 --rm --image dockersec/siege -- siege -c1 -r1 http://my-nginx-clusterip # Test app2's service kubectl run siege-app2 -it -n app2 --rm --image dockersec/siege -- siege -c1 -r1 http://my-nginx-clusterip(Added
-c1 -r1to siege for a quick test.)
4. Install Nginx Ingress Controller
We will use the Nginx Ingress controller.Note: The manifest URL below points to version 0.32.0. For production or newer clusters, always refer to the official Nginx Ingress Controller deployment documentation for the latest recommended version and instructions.
Verify the Ingress controller installation:
To simplify access to the Ingress controller via its NodePorts:
(Made variable names more descriptive and robust by checking port names first.)
Test direct access to the Ingress controller's NodePorts (replace YOUR_NODE_IP with the IP of one of your Kubernetes nodes; if using Minikube/Kind, localhost or 127.0.0.1 might work).
(Clarified localhost usage.)
5. Configure Host-Based Routing (app1)
Create
app1_ingress.yaml:Note onapiVersion:extensions/v1beta1for Ingress is deprecated and removed in Kubernetes v1.22+. Usenetworking.k8s.io/v1. The structure of thebackendfield also changes.Apply the Ingress resource for
app1:Test access to
app1: (ReplaceYOUR_NODE_IPwith your node's IP orlocalhostif appropriate.)
6. Configure Host-Based Routing (app2)
Create
app2_ingress.yaml:Apply the Ingress resource for
app2:Test access to
app1andapp2: (ReplaceYOUR_NODE_IPwith your node's IP orlocalhost.)
7. Inspect Ingress Controller Configuration (Optional)
You can check the Nginx configuration generated inside the Ingress controller pod to see how it's routing traffic.
(Made step 10 into a proper section and added command to get pod name.)
8. Configure TLS for an Ingress Resource
Create a Self-Signed Certificate and Key: For testing, we'll create a self-signed certificate. For production, use certificates from a trusted CA.
Create a Kubernetes Secret for TLS: Store the certificate and key in a TLS secret in the
app1namespace.Create
tlsapp1_ingress.yaml:Note onapiVersion:networking.k8s.io/v1beta1is also deprecated. Usenetworking.k8s.io/v1.Apply the TLS Ingress resource:
Update Your
/etc/hostsFile: To testtlsapp1.dockersec.melocally, you need to map this hostname to an IP address that routes to your Ingress controller (e.g., a Node IP, or127.0.0.1if using Minikube/Kind or port-forwarding to a node).Important: Add the following line to your
/etc/hostsfile on the machine where you are runningcurl:(Example:
127.0.0.1 tlsapp1.dockersec.meor192.168.1.100 tlsapp1.dockersec.me)Test TLS Access: (Replace
YOUR_NODE_IP_OR_LOCALHOSTwith the IP used in/etc/hosts.)(Clarified curl command for TLS testing.)
Last updated