Hands-On Lab

In this lab, we'll apply our knowledge of the Ingress API object to programmatically control how external HTTP/S traffic reaches services within our cluster. We will create an Ingress resource using Go and then demonstrate how to dynamically update it by adding new routing rules.

Objectives:

  1. Write a Go program that creates a basic Ingress resource. This Ingress should:

    • Be associated with a specific IngressClassName (ensure an Ingress Controller supporting this class is running).

    • Define a rule that routes traffic for a specific hostname (e.g., my-service.example.com) to a designated Service (e.g., my-test-service from Chapter 3 lab) on a specific port.

  2. Modify the same (or create a related) Go program to demonstrate updating an existing Ingress resource. The update should:

    • Add a new path-based rule under the same hostname (e.g., route /api traffic to a different service like my-api-service).

    • Utilize the Get-Modify-Update pattern with retry.RetryOnConflict to handle potential conflicts robustly.

  3. (Optional) Extend the creation/update logic to include TLS termination by referencing a pre-existing kubernetes.io/tls Secret.

Tasks:

  1. Navigate to the Code: Locate the Go source code for this lab within the companion GitHub repository, likely under a Chapter 4 examples directory:

  2. Prerequisites Check: Before running the code, ensure you have:

    • An Ingress Controller running in your cluster (e.g., ingress-nginx).

    • The name of the IngressClass resource associated with your controller (e.g., run kubectl get ingressclass).

    • The target backend Service(s) already created in the correct namespace (e.g., my-test-service).

    • (If testing TLS) A TLS Secret of type kubernetes.io/tls created in the target namespace.

This lab solidifies your ability to programmatically define how external traffic enters your cluster using Ingress resources. You've created routing rules and demonstrated how to safely update them, enabling automation of application exposure and traffic management within Kubernetes.

Last updated

Was this helpful?