Important note – Managing Advanced Kubernetes Resources

Remember that Ingress rules take a while to propagate across the cluster, so if you receive an error initially when you curl the endpoint, wait for 5 minutes, and you should get the response back.

Let’s curl this IP and see what we get using the following command:

$ curl 34.120.27.34

Hi there! This page was last visited on 2023-06-26, 09:28:26.

Now, let’s clean up the Ingress resource using the following command:

$ kubectl delete ingress flask-app

The simple Ingress rule is counterproductive as it routes all traffic to a singleService resource. The idea of Ingress is to use a single load balancer to route traffic to multiple targets. Let’s look at two ways to do this—path-based and name-based routing.

Path-based routing

Let’s consider an application with two versions, v1 and v2, and you want both to co-exist on a single endpoint. You can use path-based routing for such a scenario.

Let’s create the two application versions first using the imperative method by running the following commands:

$ kubectl run nginx-v1 –image=bharamicrosystems/nginx:v1 $ kubectl run nginx-v2 –image=bharamicrosystems/nginx:v2

Now, expose the two pods as ClusterIP Service resources using the following commands:

$ kubectl expose pod nginx-v1 –port=80

$ kubectl expose pod nginx-v2 –port=80

We will then create an Ingress resource using the following manifest file, nginx-app-path-ingress.yaml, which will expose two endpoints—<external-ip>/v1, which routes to the v1 Service resource, and <external-ip>/v2, which routes to the v2 Service resource:


spec:
rules:
http:
paths:
path: /v1
pathType: Prefix backend:
service:
name: nginx-v1 port:
number: 80
path: /v2
pathType: Prefix backend:
service:
name: nginx-v2
port:
number: 80

The Ingress manifest contains several rules. The http rule has two paths—/v1 and /v2, having the pathType value set to Prefix. Therefore, any traffic arriving on a URL that starts with/v1 is routed to the nginx-v1 Service resource on port 80, and traffic arriving on/v2 is routed to the nginx-v2 Service resource on port 80.

Let’s apply the manifest by using the following command:

$ kubectl apply -f nginx-app-path-ingress.yaml

Now, let’s list the Ingress resources by running the following command:

$ kubectl get ingress nginx-app -w
NAME
CLASS
HOSTS
ADDRESS
PORTS
AGE
nginx-app
*
34.120.27.34
80
114s

Now that we have the external IP, we can curl both endpoints to see what we get using the following commands:

$ curl 34.120.27.34/v1/
This is version 1
$ curl 34.120.27.34/v2/
This is version 2

Sometimes, a path-based route is not always feasible, as you might not want your users to remember the path of multiple applications. However, you can still run multiple applications using a single Ingress endpoint—that is, by using name-based routing.

Related Posts

Static provisioning – Managing Advanced Kubernetes Resources-2

As the Service resource is created, we can create a StatefulSet resource that uses the created PersistentVolume and Service resources. The StatefulSet resource manifest, nginx-manual-statefulset.yaml, looks like…

Static provisioning – Managing Advanced Kubernetes Resources-1

Static provisioning is the traditional method of provisioning volumes. It requires someone (typically an administrator) to manually provision a disk and create a PersistentVolume resource using the…

StatefulSet resources – Managing Advanced Kubernetes Resources

StatefulSet resources help manage stateful applications. They are similar to Deployment resources, but unlike a Deployment resource, they also keep track of state and require Volume and…

Managing stateful applications – Managing Advanced Kubernetes Resources

Imagine you’re a librarian in a magical library. You have a bunch of enchanted books that store valuable knowledge. Each book has a unique story and is…

Horizontal Pod autoscaling – Managing Advanced Kubernetes Resources-2

Now, let’s autoscale this deployment. The Deployment resource needs at least 1 pod replica and can have a maximum of 5 pod replicas while maintaining an average…

Horizontal Pod autoscaling – Managing Advanced Kubernetes Resources-1

Imagine you’re the manager of a snack bar at a park. On a sunny day, lots of people come to enjoy the park, and they all want…

Leave a Reply

Your email address will not be published. Required fields are marked *