Your applications team has prepared two containerized applications that you would like to run on GKE. There is a technical requirement to run both applications at different paths of the same IP address, as well as a business requirement to limit the number of Cloud load balancers deployed. For this reason, you have chosen to use the NGINX Ingress Controller to serve these applications to the Internet. In this lab, you will deploy the two applications to GKE, install the NGINX Ingress Controller, and configure Ingress objects to route traffic to each application.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create and Connect to a GKE Cluster
- From the GCP menu, select Kubernetes Engine.
- Wait for the API to be enabled. Then click Create cluster.
- Under Node Pools, select the default-pool.
- Under Node pool details > Size, change the number of nodes to "2".
- Under Node Pools, select Nodes.
- Change the Machine type to e2-small.
- Click Create to create the cluster.
- It will take a few minutes for the cluster to spin up. Once it is available, from the Clusters page, click Connect next to your cluster.
- Under Command-line access, click Run in Cloud Shell.
- When the Cloud Shell has spawned, hit Return to run the command.
- If prompted, click Authorize.
- Install the Nginx Ingress Controller
- From the Cloud Shell, run
kubectl
to install all of the Nginx Ingress Controller components by using the public provider manifesthttps://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.1/deploy/static/provider/cloud/deploy.yaml
. - Confirm the controller is installed and running by viewing its deployment.
- Find the external IP of Nginx.
- Load the IP in a web browser. If you get an Nginx 404 Not Found error, everything is working fine. Nginx is up and running, but there are no Ingress objects, so no backend is found.
- From the Cloud Shell, run
- Deploy the First Application and Ingress
Create the Hello World deployment using the container image
gcr.io/google-samples/hello-app:1.0
and expose it via a Kubernetes Service on port 8080.Create a file called "hello-ingress.yaml" to define the Ingress object for the Hello World service.
Note: The YAML you use will depend on the version of your GKE cluster. View the cluster information page to determine your Kubernetes version.
For cluster versions below 1.19:
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: hello-app-ingress annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/ssl-redirect: "false" spec: rules: - http: paths: - path: /hello backend: serviceName: hello-app servicePort: 8080
For cluster versions 1.19 or above:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: hello-app-ingress annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/ssl-redirect: "false" spec: rules: - http: paths: - path: /hello pathType: Prefix backend: service: name: hello-app port: number: 8080
Apply the manifest to the cluster.
Reload the NGINX IP address but add "/hello" to the URL. You should be able to see the Hello World service.
- Deploy the Second Application and Ingress
Create the Where Am I? deployment using the container image
gcr.io/google-samples/whereami:v1.1.1
and expose it via a Kubernetes Service on port 8080.Create a file called "whereami-ingress.yaml" to define the Ingress object for the Where Am I? service.
Note: The YAML you use will depend on the version of your GKE cluster. View the cluster information page to determine your Kubernetes version.
For cluster versions below 1.19:
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: whereami-app-ingress annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/ssl-redirect: "false" spec: rules: - http: paths: - path: /whereami backend: serviceName: whereami-app servicePort: 8080
For cluster versions 1.19 or above:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: whereami-app-ingress annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/ssl-redirect: "false" spec: rules: - http: paths: - path: /whereami pathType: Prefix backend: service: name: whereami-app port: number: 8080
Apply the manifest to the cluster.
Reload the NGINX IP address but add "/whereami" to the URL. You should be able to see the Hello World service.