Configuring the NGINX Ingress Controller on GKE

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

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
  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.
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-v0.41.2/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.
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
             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.

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

Additional Resources

To get started, log in to Google Cloud Platform by opening https://console.cloud.google.com/ in a private browser window. Then sign in using the credentials provided on the lab page.

What are Hands-on Labs

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!