OpenResty Edge works as a Kubernetes ingress controller by binding an upstream directly to a K8s service. The Edge Admin watches the Kubernetes API server and auto-syncs the upstream server list as pods come online or go offline—no manual edits, and no gateway reload, restart, or binary upgrade. The Edge gateway servers can run inside or outside the Kubernetes Cluster. Below is a full walkthrough of managing traffic to the backend applications running inside your Kubernetes containers.

OpenResty Edge acting as a Kubernetes ingress controller, routing traffic to pods inside a K8s cluster

In this tutorial, we will create a Kubernetes upstream in an Edge application. The Edge gateway servers may run inside or outside the Kubernetes Clusters. The Edge Admin servers continuously monitor the Kubernetes Clusters via its API servers. And it updates the upstream server list automatically according to the online and offline events of the Kubernetes Nodes (or containers).

OpenResty Edge Admin monitoring the Kubernetes API server and auto-updating the upstream server list on pod online and offline events

How to create and use Kubernetes upstream

Now let’s go to a web console of OpenResty Edge. This is our sample deployment of the console. Every user has their own local deployment.

OpenResty Edge web console dashboard for the sample deployment

First, we need a gateway server in a dedicated gateway partition that can connect to the Kubernetes services.

Gateway partition in OpenResty Edge that can connect to Kubernetes services

Let’s go to the Gateway Partitions page.

Navigating to the Gateway Partitions page in OpenResty Edge

We have already created a gateway partition, kubernetes-test-partition,

The kubernetes-test-partition gateway partition in OpenResty Edge

which contains a gateway cluster, kubernetes-test-cluster.

The kubernetes-test-cluster gateway cluster inside the partition

We need a separate gateway partition here because not all our gateway servers can connect to our Kubernetes services.

Go to the kubernetes-test-cluster cluster.

Opening the kubernetes-test-cluster gateway cluster in OpenResty Edge

There is one gateway server already defined in this gateway cluster. We need to make sure that this gateway server can reach our Kubernetes Cluster.

Edge gateway server in the cluster that can reach the Kubernetes Cluster

Create Kubernetes Cluster

Before we can create a new Kubernetes upstream in an Edge application, we first need to register our Kubernetes Cluster globally.

Goto the Kubernetes page.

Navigating to the Kubernetes page in OpenResty Edge Admin

Click this button to add a new Kubernetes Cluster.

Button to add a new Kubernetes Cluster in OpenResty Edge

The OpenResty Edge Admin needs to establish connections to Kubernetes’ HTTPS API servers for any new notifications.

Enter the host name or IP address of our Kubernetes API server.

Entering the Kubernetes API server host name or IP address

Then enter its port number.

Entering the Kubernetes API server port number

Next we enter the name of the kubernetes Cluster

Entering the name of the Kubernetes Cluster in OpenResty Edge

We disable the SSL certificate verification. This is because our Kubernetes API server’s certificate is self-signed.

Disabling SSL certificate verification for the self-signed Kubernetes API server

We also need a token with enough privileges to access the Kubernetes API server.

Field for the token used to access the Kubernetes API server

Click on the link “How to generate this token”.

Opening the “How to generate this token” help link in OpenResty Edge

This window explains how to generate one from your own Kubernetes deployment. Now let me demonstrate the process.

Close this window.

Closing the token help window in OpenResty Edge

We need to prepare a token.yml specification file. One sample of this file is as follows. It is for creating a service account with reading access to the

Sample token.yml spec creating a Kubernetes service account with read access

namespaces,

token.yml granting read access to Kubernetes namespaces

services,

token.yml granting read access to Kubernetes services

endpoints, and

token.yml granting read access to Kubernetes endpoints

Pods objects.

token.yml granting read access to Kubernetes Pods objects

Then we create the service account using the following command.

kubectl apply -f /root/token.yml

Creating the Kubernetes service account with kubectl apply -f token.yml

Finally, we use the following command to get the token of the service account.

Command to retrieve the Kubernetes service account token

The text after “token:” is the token we need.

Kubernetes service account token shown after the token: label

Now we have a token to access the Kubernetes API server.

Paste the API token we just created.

Pasting the Kubernetes API token into OpenResty Edge

Click the Create button.

Clicking Create to register the Kubernetes Cluster in OpenResty Edge

Create Kubernetes upstream

Now that we have the Kubernetes Cluster registered globally. It’s time to create an upstream in an Edge application to make use of this cluster.

Kubernetes Cluster registered globally in OpenResty Edge

Go to the application list page.

Opening the Edge application list page

We already prepared an Edge application named www.kubernetes-edge-test.com.

The www.kubernetes-edge-test.com Edge application

Our application is mapped to the gateway partition we showed earlier.

Edge application mapped to the Kubernetes gateway partition

Enter the application.

Entering the Edge application in OpenResty Edge

Go to the Upstreams page.

Opening the Upstreams page in the Edge application

Click New Kubernetes Upstream.

Clicking New Kubernetes Upstream in OpenResty Edge

Enter the name of the Kubernetes upstream, “my kubernetes backend”.

Naming the Kubernetes upstream “my kubernetes backend”

Select a Kubernetes Cluster as the target.

Selecting a Kubernetes Cluster as the upstream target

We select the one we just created at the beginning of this tutorial.

Selecting the Kubernetes Cluster created earlier in this tutorial

Now select the target Kubernetes namespace.

Selecting the target Kubernetes namespace for the upstream

Choose the namespace named “default”. You may have a different namespace though.

Choosing the “default” Kubernetes namespace

Select a Kubernetes service from a list.

Selecting a Kubernetes service from the list

We select the “test-hello” service.

Selecting the “test-hello” Kubernetes service

And also the service port.

Selecting the Kubernetes service port

It’s port 80 in our case.

Selecting port 80 for the Kubernetes service

Save the new upstream.

Saving the new Kubernetes upstream in OpenResty Edge

Now we have successfully created a new Kubernetes upstream.

New Kubernetes upstream successfully created in OpenResty Edge

The upstream server addresses have already appeared.

Kubernetes upstream server addresses populated automatically

They are Kubernetes Nodes or containers automatically synchronized from the Kubernetes Cluster.

Upstream servers auto-synchronized from the Kubernetes Cluster

Create a page rule that uses Kubernetes upstream

Just as with ordinary upstreams, we still need to create a new Page Rule to make use of this new Kubernetes upstream.

Go to the Page Rules page.

Opening the Page Rules page in the Edge application

Click the “New Rule” button.

Clicking the “New Rule” button in OpenResty Edge

Enable the Proxy action.

Enabling the Proxy action in the page rule

Click on the “Proxy to upstream” drop-down list.

Opening the “Proxy to upstream” drop-down list

Select the Kubernetes upstream, “my kubernetes backend”, we just created.

Selecting the “my kubernetes backend” Kubernetes upstream in the page rule

Save this page rule.

Saving the page rule that proxies to the Kubernetes upstream

We need to make a new configuration release for this Edge application, as always.

Making a new configuration release for the Edge application

Click this button.

Confirming the configuration release in OpenResty Edge

Ship it!

Shipping the new OpenResty Edge configuration release

It is fully synchronized.

Configuration fully synchronized in OpenResty Edge

Now the new page rule has been pushed to all the gateway clusters and servers.

OpenResty Edge pushing the new page rule to every gateway cluster and server, frame 1

OpenResty Edge synchronizing the configuration across gateway servers, frame 2

OpenResty Edge configuration fully synchronized to all gateway servers, frame 3

Our configuration changes do NOT require server reload, restart, or binary upgrade. So it’s very efficient and scalable.

Configuration changes synchronized to all OpenResty Edge gateway servers without any reload or restart

Test: scale the pods and watch the upstream auto-update

Next, let’s find the Edge gateway server in the right partition to actually test it.

Go to the Gateway Clusters page.

Opening the Gateway Clusters page in OpenResty Edge

Find the right gateway server here.

Finding the right Edge gateway server for testing

Its public IP address ends with .196.

Edge gateway server whose public IP address ends with .196

Copy this IP address so that we can use it on the command line.

On the terminal, let’s try to access the Kubernetes service through this gateway server.

Preparing to access the Kubernetes service through the Edge gateway server on the terminal

Note that we use the gateway server IP address we just copied.

Using the copied Edge gateway server IP address in the curl command

Run this command.

Running the curl command against the Kubernetes service via OpenResty Edge

Now we see that the access to the service was successful. In the rest of the tutorial, we’d modify the configuration of the Kubernetes service.

Successful response from the Kubernetes service through OpenResty Edge

We will increase the number of the Kubernetes Nodes to 3 on the fly.

kubectl scale --replicas=3 deployment test-hello

Scaling the test-hello deployment to three replicas with kubectl

It was scaled successfully.

The test-hello deployment scaled successfully to three replicas

Let’s check the new Nodes.

kubectl get pods -o wide

Checking the new pods with kubectl get pods -o wide

There are indeed three Kubernetes Nodes now.

Three Kubernetes Nodes now running after scaling the deployment

The Kubernetes upstream should be automatically updated by Edge Admin to reflect this change.

Let’s go back to our Edge application page to check it out.

Returning to the OpenResty Edge application page to check the upstream

OpenResty Edge application page after scaling the Kubernetes pods

Return to the Upstreams page.

Returning to the Upstreams page in OpenResty Edge

Refresh the Upstreams page to avoid any stale data.

Refreshing the Upstreams page to avoid stale data

Yay! The Kubernetes upstream indeed has 3 servers now!

Kubernetes upstream now showing three servers after auto-update

Similarly, if there are fewer Kubernetes Nodes, Edge Admin will also automatically update the upstream. This is what I’d like to cover today.

Edge Admin automatically updating the upstream when Kubernetes Nodes change

For the bigger picture of how OpenResty Edge manages the full Kubernetes gateway node lifecycle—across autoscaling events and multiple clusters—see Automating Kubernetes Gateway Node Lifecycle with OpenResty Edge.

Frequently asked questions

Can OpenResty Edge be used as a Kubernetes ingress controller?

Yes. OpenResty Edge acts as an ingress controller for Kubernetes Clusters, managing traffic to the backend applications running inside the Kubernetes containers. You register your Kubernetes Cluster in Edge Admin, create a Kubernetes upstream bound to a K8s service, and route to it with a page rule. The Edge gateway servers may run inside or outside the Kubernetes Cluster.

How does OpenResty Edge update upstreams when pods scale up or down?

The Edge Admin servers continuously monitor the Kubernetes Cluster through its API server and update the upstream server list automatically as Kubernetes Nodes (or containers) come online and go offline. In this tutorial, scaling the test-hello deployment to three replicas made the Kubernetes upstream automatically show three servers, with no manual changes.

Does OpenResty Edge need a reload or restart to update a Kubernetes upstream?

No. Configuration changes and upstream updates in OpenResty Edge do not require a server reload, restart, or binary upgrade. Changes are pushed to all gateway clusters and servers and synchronized live, which keeps the process efficient and scalable under high concurrency.

Can the OpenResty Edge gateway run outside the Kubernetes cluster?

Yes. The Edge gateway servers may run inside or outside the Kubernetes Cluster. The only requirement is that the gateway server in the dedicated gateway partition can reach your Kubernetes services, while the Edge Admin connects to the Kubernetes HTTPS API server to track pod events.

What is OpenResty Edge

OpenResty Edge is our all-in-one gateway software for microservices and distributed traffic architectures. It combines traffic management, private CDN construction, API gateway, security, and more to help you easily build, manage, and protect modern applications. OpenResty Edge delivers industry-leading performance and scalability to meet the demanding needs of high concurrency, high load scenarios. It supports scheduling containerized application traffic such as K8s and manages massive domains, making it easy to meet the needs of large websites and complex applications.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.