Reputation: 99
I currently have a load balancer per pod. In my instance 2 pods with the following YAML definitions.
apiVersion: v1
kind: Service
metadata:
name: service1
spec:
ports:
- name: https-service1
port: 6379
targetPort: 6379
selector:
app: service1-consoleapp
type: LoadBalancer
apiVersion: v1
kind: Service
metadata:
name: service2
spec:
ports:
- name: https-service2
port: 443
targetPort: 443
selector:
app: service2-consoleapp
type: LoadBalancer
When I apply the above 2 yaml files I will get 2 external ip's that I then use to configure my A records in my dns subdomains.
service1.company.com => external ip 1 for service1-consoleapp
service2.company.com => external ip 2 for service2-consoleapp
Is there a way to combine the YAML file into one, so that I can only use one IP address instead of 2 ?
Also , it looks like in ingress you can do it but not sure how I deal with the "host" requirement.
Can someone please explain how the routing will work as I'm not sure what values should be in the path property ?
Will I still get 2 external ip's on this that I can use to populate the dns subdomains ?
spec:
rules:
- host: service1.company.com
http:
paths:
- backend:
serviceName: service1
servicePort: 6379
path: ??
- host: service2.company.com
http:
paths:
- backend:
serviceName: service2
servicePort: 433
path: ??
The result I'm looking for is if I type
service1.company.com:6379 in my browser then I should hit the pod endpoint (service1-consoleapp) and if I type
service2.company.com:443 in my browser then I should hit the pod endpoint (service2-consoleapp).
where the service1.company.com and service2.company.com is on the same IP address.
thanks in advance.
Upvotes: 2
Views: 2990
Reputation: 44549
The ingress resource that you have currently should work. Remove the path
section completely. Also in your DNS you need to create subdomains service1.company.com
, service2.company.com
and a A record
to point to IP of the loadbalancer.
This loadBalancer is the one which will route traffic form outside to ingress controller pods and ingress controller will forward the traffic to the backend pods according to rules defined in the ingress resource. The host
rule works this way - if a HTTP request has a Host
header service1.company.com
ingress controller will send that request to service1
and if it has a Host
header service2.company.com
ingress controller will send that request to service2
When you deploy a ingress controller such as Nginx you need to create a LoadBalancer
type service.So you will have only one loadBalancer which is for exposing ingress controller pods.
Upvotes: 1
Reputation: 8122
You better work with Microsoft documentation - Create an ingress controller in Azure Kubernetes Service (AKS).
From the docs:
An ingress controller is a piece of software that provides reverse proxy, configurable traffic routing, and TLS termination for Kubernetes services. Kubernetes ingress resources are used to configure the ingress rules and routes for individual Kubernetes services. Using an ingress controller and ingress rules, a single IP address can be used to route traffic to multiple services in a Kubernetes cluster.
Follow the documentation and set an ingress.
Later on, Follow Kubernetes documentation as @CSharpRocks offered in the comments.
From the docs:
If you create an Ingress resource without any hosts defined in the rules, then any web traffic to the IP address of your Ingress controller can be matched without a name based virtual host being required.
For example, the following Ingress resource will route traffic requested for first.bar.com to service1, second.foo.com to service2, and any traffic to the IP address without a hostname defined in request (that is, without a request header being presented) to service3.
Yaml example:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: name-virtual-host-ingress
spec:
rules:
- host: first.bar.com
http:
paths:
- backend:
serviceName: service1
servicePort: 80
- host: second.foo.com
http:
paths:
- backend:
serviceName: service2
servicePort: 80
- http:
paths:
- backend:
serviceName: service3
servicePort: 80
More about Path types.
Upvotes: 2