Start Sending Traffic to Your Kubernetes Cluster with NGINX

by

in

If you’ve recently learned about Kubernetes or are just starting to grasp its basics and concepts, you might be wondering how to start using it effectively. We understand – Kubernetes can be difficult! This guide is designed to help you get more comfortable with interacting with a local Kubernetes cluster while providing a solid introduction to using Kubernetes.

Installation Prerequisites

Before diving into the installation process, it’s crucial to properly set up your environment. These are the prerequisites you need to have in place to ensure a smooth and successful installation:

  • Kind – There are numerous ways to get started with Kubernetes, and installing with the official distribution can be quite intimidating. For this guide, we’ll be using a packaged solution called Kind, which lets you easily set up a Kubernetes cluster on your local machine.
  • Docker – Kind uses Docker.
  • Helm – We’ll use Helm to easily deploy NGINX Gateway Fabric, enabling us to configure traffic in our cluster.

Deploy Kind

To deploy a Kubernetes cluster on your local machine, run this command:

Install Gateway CRDs

Run the following command to install the Gateway API CustomResourceDefinitions (CRDs). You can learn more on the official Gateway API site. For now, all you need to know if that this step allows us to use custom resources to manage our Kubernetes cluster.

Install NGINX Gateway Fabric

Run the following command to install NGINX Gateway Fabric. This will consume Gateway API CRDs and configure an NGINX instance accordingly.

Deploy the Cafe App

To deploy a sample application in your Kubernetes cluster, run the commands below. The application will respond with a simple HTTP response when it receives a request:

Retrieve the NGINX Gateway Fabric Pod Name

To list the name of your NGINX Gateway Fabric Pod, which you will need for the next step, run:

Port Forward to the App

To access the application on your local Kubernetes cluster, run the following command:

At a high level, because this Kubernetes cluster is running on your local machine, you can’t expose the applications to an external IP endpoint. To set up a connection between your computer and your local Kubernetes cluster, use the above port-forward command, which links your computer to the NGINX Gateway Fabric Pod, allowing you to access your applications.

Send Traffic to the App

To send cURL requests to your NGINX Gateway Fabric Pod, which will route them to your Kubernetes applications, run:

If it worked correctly, you should see responses similar to the these:

Takeaways

Congratulations! If everything went right, you’ve successfully set up a Kubernetes cluster on your local machine, deployed a simple application, configured traffic routing through the Gateway API resources, and interacted with an application in the Kubernetes cluster.

If you want to learn more about how we configured traffic flow, check out the official NGINX Gateway Fabric documentation. You can also explore cool features and more examples of simple applications on our GitHub repository.