This lesson explores Kubernetes Ingress Networking by deploying an Ingress Controller to route traffic to applications in different namespaces.
In this lesson, we explore Kubernetes Ingress Networking by deploying an Ingress Controller and configuring it to route traffic to two applications located in different namespaces. We will deploy a “video” app and a “wear” app within the app-space namespace while managing the Ingress Controller in its own namespace.
Next, within the ingress-space namespace, create a ConfigMap (which may contain Nginx configuration data) and a Service Account. The related Roles and RoleBindings for the service account ingress-serviceaccount are pre-configured. Verify the roles and role bindings with:
Copy
Ask AI
root@controlplane:~# k get roles -n ingress-spaceNAME CREATED ATingress-role 2022-04-19T21:05:42Zroot@controlplane:~# k get rolebindings -n ingress-spaceNAME ROLE AGEingress-role-binding Role/ingress-role 20sroot@controlplane:~# k describe role ingress-role -n ingress-spaceName: ingress-roleLabels: app.kubernetes.io/name=ingress-nginx app.kubernetes.io/part-of=ingress-nginxAnnotations: <none>PolicyRule: Resources Non-Resource URLs Resource Names Verbs --------- ------------------ -------------- ----- configmaps [] [] configmaps [] [ingress-controller-leader-nginx] endpoints [] [] namespaces [] [] pods [] [] secrets [] []
Deploy the Ingress Controller using the following manifest. This YAML configuration ensures that the controller runs within the ingress-space namespace and uses the pre-created service account. Note the proper indentation, namespace specification, and container arguments:
To allow external access to your Ingress Controller, expose it using a Service of type NodePort. Execute the following command to expose the deployment:
Now, create an Ingress resource to route traffic to the applications deployed in the app-space namespace. The Ingress rules will direct:
Requests to /wear to the wear-service on port 8080.
Requests to /watch to the video-service on port 8080.
Run the following command to create the Ingress:
Copy
Ask AI
root@controlplane:~# k create ingress ingress-wear-watch -n app-space --rule="/wear=wear-service:8080" --rule="/watch=video-service:8080"ingress.networking.k8s.io/ingress-wear-watch created
Verify the Ingress resource with:
Copy
Ask AI
root@controlplane:~# k get ingress -n app-spaceNAME CLASS HOSTS ADDRESS PORTS AGEingress-wear-watch <none> * <none> 80 8s
If you observe that requests to the /watch path are not reaching the intended video service, and the logs remain inactive, review the Ingress Controller logs. You might see repeated HTTP 308 redirects indicating SSL redirection is enforced:
Perform a final check of the service and Ingress statuses to confirm that everything is functioning as expected:
Copy
Ask AI
root@controlplane:~# k get svc -n app-spaceNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdefault-http-backend ClusterIP 10.109.67.66 <none> 80/TCP 10mvideo-service ClusterIP 10.99.96.249 <none> 8080/TCP 10mwear-service ClusterIP 10.105.104.69 <none> 8080/TCP 10mroot@controlplane:~# k get ingress -n app-spaceNAME CLASS HOSTS ADDRESS PORTS AGEingress-wear-watch <none> * 80 3m24s
This confirms that the Ingress Controller is properly deployed, exposed, and routing traffic correctly with SSL redirection disabled.That concludes the lab on Kubernetes Ingress Networking. For further reading on Ingress configurations and best practices, consider exploring the following resources: