Test the Ingress Resource
Finally, we can test the Ingress resource to make sure everything is working correctly.
First, determine the IP address of the node:
kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready control-plane 93s v1.26.1 192.168.49.2 <none> Ubuntu 20.04.5 LTS 5.15.0-56-generic docker://20.10.23
This command will get the kubernetes node address, The IP address labeled as INTERNAL-IP
.
Next, add an entry to your /etc/hosts
file to map the test.local
domain to the IP address of the node:
echo "<IP_ADDRESS> test.local" | sudo tee -a /etc/hosts
Replace <IP_ADDRESS>
with the internal IP address of the node address. For example:
echo "192.168.49.2 test.local" | sudo tee -a /etc/hosts
Then, get service nodeport for ingress-nginx
.
kubectl get services -n ingress-nginx
This command will dcurisplay a list of services in the ingress-nginx
namespace. Look for the nginx-ingress-controller
service and note its NodePort
.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.104.99.158 <pending> 80:32518/TCP,443:31620/TCP 2m45s
ingress-nginx-controller-admission ClusterIP 10.100.46.109 <none> 443/TCP 2m45s
Finally, use curl
to make an HTTP request to the Ingress endpoint:
curl test.local:NodePort
For example:
curl test.local:32518
Replace <NodePort>
with the NodePort
of the nginx-ingress-controller
service.
If everything is set up correctly, you should see the Nginx welcome page.
You can also test the Ingress by using a web browser to visit test.local:<NodePort>/nginx
.
Congratulations, you have successfully set up an Ingress resource in Kubernetes and tested it to ensure that it is working correctly.