Dynamically assign container URL based on criteria using Kubernetes

77 views Asked by At

Is Kubernetes capable of assigning URLs depending on particular constraints/programming logic? The following is the high-level behavior that I'm after.

  1. Container A is deployed.
  2. Kubernetes assigns it my.container.a.url.com or my.container.a.url.net depending on a particular criteria, such as if the container is for external or internal use.
1

There are 1 answers

0
danielepolencic On

Without context on what you're trying to achieve it's quite hard to answer. But I'll try anyway.

In Kubernetes you don't expose bare containers, but you wrap them in Pods and expose services - which are sort of load balancers for a group of containers.

In your particular case, you can create two services, one for internal and the other for external use. The former is connected to all Pods (containers) for internal use, the latter to all Pods (containers) for external use.

You can learn more about service here: https://kubernetes.io/docs/concepts/services-networking/service/

Once you have a service, you still aren't able to connect to it from the outside world. Depending on your requirement you can:

  1. create an Ingress and expose your services to the internet: https://kubernetes.io/docs/concepts/services-networking/ingress/
  2. Edit your services and make them use NodePorts https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport