Even if domain name my.domain.com
can be an internal or intranet domain name, resolved by a company's internal DNS server, you would still need an Ingress Controller to handle traffic that originates "outside" of the Kubernetes cluster, even though it is within the same private network.
So you would still generally use a LoadBalancer
or NodePort
service for the Ingress Controller, and ClusterIP
services for your application services inside the cluster.
Meaning the my.domain.com
needs to be configured on the company's internal DNS server to resolve to the IP address of the Ingress Controller's service. Then:
- The Ingress Controller receives the request and checks its Ingress rules.
- An Ingress rule matches
my.domain.com
to a particular service within the cluster (let's call it my-service).
- The Ingress Controller forwards the request to
my-service
.
my-service
, which is typically of type ClusterIP
, receives the request and sends it to the appropriate pod.
The Ingress Controller could be a LoadBalancer
service if the Kubernetes cluster is running in a cloud environment that supports it, or it could be a NodePort
service if running in an environment that does not support LoadBalancers (like a bare-metal cluster).
MetalLB is a load balancer implementation for bare metal Kubernetes clusters. It aims to provide the services of a LoadBalancer
for these clusters which typically do not have a native load balancer available like those in cloud environments.
So in the context of a bare metal Kubernetes cluster using MetalLB, you would typically use a LoadBalancer
service, not a NodePort
service, for your Ingress controller.
Check you current setup with:
kubectl get ingresses.networking.k8s.io -o yaml
kubectl get services -o yaml
kubectl describe ingress <your-ingress>
kubectl describe svc <your-service>
kubectl get pods -n ingress-nginx
Compare it with a typical setup, assuming that your Ingress controller (e.g., NGINX or Traefik) is already installed and configured correctly:
my-app-deployment.yaml
: This file contains the definition of the Deployment for your application.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0
ports:
- containerPort: 8080
my-service.yaml
: This file contains the definition of the Service that exposes your application within the cluster.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
my-ingress.yaml
: This file contains the definition of the Ingress that exposes your service to the outside world.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: my.domain.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: my-service
port:
number: 80
In your DNS, my.domain.com should point to the external IP provided by MetalLB for your Ingress controller. If you are testing locally and have no DNS set up, you can add an entry to your hosts file with the format <ip-address> my.domain.com
where <ip-address>
is the external IP of your Ingress controller.