Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Labs

Configuring the NGINX Ingress Controller on GKE

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.

Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Apr 09, 2021

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create and Connect to a GKE Cluster

    1. From the GCP menu, select Kubernetes Engine.
    2. Wait for the API to be enabled. Then click Create cluster.
    3. Under Node Pools, select the default-pool.
    4. Under Node pool details > Size, change the number of nodes to "2".
    5. Under Node Pools, select Nodes.
    6. Change the Machine type to e2-small.
    7. Click Create to create the cluster.
    8. 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.
    9. Under Command-line access, click Run in Cloud Shell.
    10. When the Cloud Shell has spawned, hit Return to run the command.
    11. If prompted, click Authorize.
  2. Challenge

    Install the Nginx Ingress Controller

    1. From the Cloud Shell, run kubectl to install all of the Nginx Ingress Controller components by using the public provider manifest https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.1/deploy/static/provider/cloud/deploy.yaml.
    2. Confirm the controller is installed and running by viewing its deployment.
    3. Find the external IP of Nginx.
    4. 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.
  3. Challenge

    Deploy the First Application and Ingress

    1. 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.

    2. 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
      
    3. Apply the manifest to the cluster.

    4. Reload the NGINX IP address but add "/hello" to the URL. You should be able to see the Hello World service.

  4. Challenge

    Deploy the Second Application and Ingress

    1. 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.

    2. 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
      
    3. Apply the manifest to the cluster.

    4. Reload the NGINX IP address but add "/whereami" to the URL. You should be able to see the Hello World service.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans