Create Kubernetes Nginx Ingress Controller for External API Traffic
This lab will teach how to install and setup the Nginx Ingress Controller, Deploy a ready made Programming Languages themed API into a Kubernetes cluster, Create and deploy an Ingress resource to expo
In the AWS Management Console search bar, enter EC2, and click the EC2 result under Services.
In the left-hand menu, click on Instances, select the k8s.cluster.cloudacademy.platform.instance EC2 instance, and locate and copy the IPv4 Public IP address.
The web-based CloudAcademy IDE has been configured to listen for inbound connections on port 3000 using HTTP. Using your browser, navigate to the IDE hosted on the k8s.cluster.cloudacademy.platform.instance EC2 instance using the public IP address you just copied.
Within the Files Explorer pane right-click on the project/code/cillium folder and then select the Open in Terminal option to launch the integrated terminal
Use the kubectl command to install the Cilium Kubernetes CNI plugin into the local Kubernetes cluster. Within the terminal enter the following command.
kubectl apply -f install.1.6.1.yaml
Use both watch and kubectl to view the Cilium pods starting up. Within the terminal enter the following commands
watch -n2 kubectl -n kube-system get pods
Install Nginx Ingress Controller
Change directories. Within the terminal enter the following command
cd /home/project/code/ingress-nginx
Install the Nginx Ingress Controller resources. Within the terminal enter the following
kubectl apply -f install.0.32.0.yaml
Examine the new Nginx Ingress Controller resources created by the previous command. Within the terminal run the following commands
kubectl get all -n ingress-nginx
Behind the scenes minikube is being used to provide the Kubernetes cluster within this lab environment. To facilitate internet inbound traffic to the Nginx ingress controller hosted when using minikube for the cluster - you'll need to make a networking update (hostNetwork: true) to the ingress-nginx-controller deployment resource. To accomplish this, first generate a local copy of the YAML configuration for the ingress-nginx-controller deployment resource. Within the terminal run the following commands.
kubectl get deploy ingress-nginx-controller -n ingress-nginx -o yaml >> nginx-ingress-controller.yaml
The nginx-ingress-controller.yaml manifest file is very large. To make it easier to inject the new hostNetwork setting into the exact required location, use the provided yq utility. The yq utility will first need to be made executable. Within the terminal run the following commands.
chmod +x ../utils/yq
Confirm that the yq utility is now executable. Within the terminal run the following commands
ls -la ../utils/yq
Inject the hostNetwork: true setting into the nginx-ingress-controller.yaml file. Within the terminal run the following commands.
../utils/yq w nginx-ingress-controller.yaml spec.template.spec.hostNetwork true > nginx-ingress-controller-v2.yaml
Delete and recreate the updated ingress-nginx-controller deployment. Within the terminal run the following commands
Within the Files pane, open the project/code/API/lab-code/deploy-api.yaml file within the editor. Take some time to review the Kubernetes resources that are going to be provisioned within the cluster:
Ensure that you are in the lab-code directory. Within the terminal run the following commands
cd /home/project/code/API/lab-code
You will now create all of the API resources declared within the deploy-api.yaml file. Within the terminal run the following commands
kubectl apply -f deploy-api.yaml
Confirm that all of the pods have launched successfully. Within the terminal run the following commands.
kubectl get pods
Confirm that the service has launched successfully. Within the terminal run the following commands
kubectl get services
Deploy the API Ingress Resource
Within the Files pane, open the lab-code/deploy-api-ingress.yaml file within the editor. Take some time to review the Kubernetes Ingress resource that is going to be provisioned within the cluster.
Ensure that you are in the lab-code directory. Within the terminal run the following commands
cd /home/project/code/API/lab-code
Before you create the Kubernetes Ingress resource, you need to update the deploy-api-ingress.yaml file by replacing the X.X.X.X placeholder with the public IP address assigned to the EC2 instance that the Kubernetes cluster is running on. Within the terminal run the following commands
EXTIP=`curl ipinfo.io/ip`
sed -i -e "s/X.X.X.X.nip.io/$EXTIP.nip.io/g" deploy-api-ingress.yaml
Create the new Kubernetes Ingress resource for the API service. Within the terminal run the following commands.
kubectl apply -f deploy-api-ingress.yaml
Confirm that all of the ingress resources has been created successfully. Within the terminal run the following commands.
kubectl get ingress
Perform External API Test
Within the terminal execute the following curl command to exercise the API