1

I've install Kubernetes and Metalb and ingress services and controllers on my ubuntu server and I want to connect domains to my service with ingress in my Kubernetes. The problem is that when I map a domain to a service, when I can get the domain on my server with changing the host file and connecting domain to external ip of ingress controller , it connects to the domain, but when I enter domain on my browser it on my local computer, for testing it. And I change the host file so that it reads from the server and I type the domain, for example localhost.com, it goes to the 404 page of nginx, and when I type localhost.com:33721, which is the node port of the ingress controller, it connects to my service. Does anyone know where the problem is or how I can map my service to my domain correctly? Am I correct with this or what is the best practice to map domain to my service?

I tried Many things i change the type of ingress controller to loadbalancer or node port and i tried to do port forward so that my server directly forward to ip of my ingress controller and many things else

  • Please consider providing a Minimal Reproducible Example so others can assist more effectively: https://stackoverflow.com/help/minimal-reproducible-example – Blender Fox May 20 '23 at 09:05
  • Please provide enough code so others can better understand or reproduce the problem. – Community May 21 '23 at 13:38

1 Answers1

0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250