You are on page 1of 8

Lab: Kubernetes Ingress

Introduction
In this lab we will see how to use NginX-based Kubernetes Ingress Controllers to make
Kubernetes services available to the outside world. We will demonstrate how three applications
share the same IP address and port, while ingress rules decide, which URL pattern is routed to
which application.

Objectives:
• Install Nginx Controller
• Install Ingress Service
• Create Apps
• Access Apps via Nginx Ingress
Flowchart:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
Note: Ensure you have running cluster deployed & configured.
1. Ensure that you have logged-in as root user with password as linux on kube-master node.

1.1 Let us clone the git repository which contains manifests required for this exercise, by executing the
below command.

# git clone https://github.com/EyesOnCloud/k8s-ingress.git


Output:

1.2 Let us view the NginX controller mainfest, by executing the below command.

# cat -n ~/k8s-ingress/mandatory.yaml

1.3 Let us create the mandatory elements, by executing the below command.

# kubectl apply -f ~/k8s-ingress/mandatory.yaml


Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.4 Let us verify the installation, by executing the below command.

# kubectl get all -n ingress-nginx


Output:

1.5 Let us view the manifest for Ingress service, by executing the below command.

# cat -n ~/k8s-ingress/ingress-service.yaml

Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.6 Let us create the service, by executing the below command.

# kubectl apply -f ~/k8s-ingress/ingress-service.yaml


Output:

1.7 Let us verify the service, by executing the below command.

# kubectl get svc -n ingress-nginx -o wide


Output:

1.8 Let us view the manifest for webapp - deployment & service, by executing the below
command.
# cat -n ~/k8s-ingress/webapp1.yaml

Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.9 Let us create three deployments and services, and we will see, how the ingress controller
allows us to access all of those applications on the same IP address and port on different
resource URLs.

# kubectl apply -f ~/k8s-ingress/webapp1.yaml


Output:

# kubectl apply -f ~/k8s-ingress/webapp2.yaml


Output:

# kubectl apply -f ~/k8s-ingress/webapp3.yaml


Output:

1.10 Let us view the ingress manifest, by executing the below command.

# cat -n ~/k8s-ingress/webapp-ingress.yaml
Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
Note: In the above example, we try to reach webapp1 and webapp2 via the resource /webapp1
and /webapp2, respectively. All other resources will be routed to webapp3.

1.11 Let us create the ingress, by executing the below command.

# kubectl apply -f ~/k8s-ingress/webapp-ingress.yaml


Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.12 Let us capture the Cluster IP in a variable by executing the below command.

# CLUSTER_IP=$(kubectl get svc -n ingress-nginx | grep


ingress-nginx | awk '{print $3}')

1.13 Let us access the application webapp1, by executing the below command.

# curl -H "Host: my.kubernetes.example" $CLUSTER_IP/webapp1


Output:

1.14 Let us access the application webapp2, by executing the below command.

# curl -H "Host: my.kubernetes.example" $CLUSTER_IP/webapp2


Output:

1.15 Let us access the application webapp2, by executing the below command.

# curl -H "Host: my.kubernetes.example" $CLUSTER_IP


Output:

1.16 Let us access the application via nodeport service, let us capture the nodeport by
executing below command.

# NODE_PORT=$(kubectl get svc -n ingress-nginx | grep


ingress-nginx | awk '{print $5}' | awk -F '[:/]' '{print
$2}')

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/
1.17 Let us access the application via nodeport service, by executing below commands.

# curl -H "Host: my.kubernetes.example" kube-


node1:$NODE_PORT/webapp1
Output:

# curl -H "Host: my.kubernetes.example" kube-


node1:$NODE_PORT/webapp2
Output:

# curl -H "Host: my.kubernetes.example" kube-node1:$NODE_PORT

Output:

1.18 Let us cleanup, by executing below command.

# kubectl delete -f ~/k8s-ingress/

Output:

Student Material – Do Not Re-distribute. For any queries contact:


naushad.p.tech@gmail.com or https://www.linkedin.com/in/naushadpasha/

You might also like