A.Dumas
A.Dumas

Reputation: 3267

Kubernetes nginx ingress redirect domains to cluster

I want to redirect two namecheap domains testA.com and testB.com to two different services (websites) on my raspberry pi cluster.

I set everything up using an updated form from this guide. This means that k3s, metalb, nginx ingress and cert-manager are fully deployed and working.

% kubectl get pods --all-namespaces
NAMESPACE      NAME                                                      READY   STATUS    RESTARTS   AGE
kube-system    metallb-speaker-bsxfg                                     1/1     Running   1          30h
kube-system    metallb-speaker-6pwsb                                     1/1     Running   1          30h
kube-system    nginx-ingress-ingress-nginx-controller-7cc994599f-db285   1/1     Running   1          28h
cert-manager   cert-manager-7998c69865-754mr                             1/1     Running   2          27h
kube-system    metallb-speaker-z8p97                                     1/1     Running   1          30h
webserver      httpd-554794f9fd-npd4g                                    1/1     Running   1          21h
kube-system    metallb-controller-df647b67b-2khlr                        1/1     Running   1          30h
kube-system    coredns-854c77959c-dl74f                                  1/1     Running   2          33h
cert-manager   cert-manager-webhook-7d6d4c78bc-97g2g                     1/1     Running   1          27h
kube-system    metrics-server-86cbb8457f-2vqmt                           1/1     Running   3          33h
cert-manager   cert-manager-cainjector-7b744d56fb-bvwjd                  1/1     Running   2          27h
kube-system    local-path-provisioner-5ff76fc89d-vbqs9                   1/1     Running   4          33h
% kubectl get services  -n kube-system -o wide                     
NAME                                               TYPE           CLUSTER-IP      EXTERNAL-IP       PORT(S)                      AGE   SELECTOR
nginx-ingress-ingress-nginx-controller-admission   ClusterIP      10.43.116.250   <none>            443/TCP                      28h   app.kubernetes.io/component=controller,app.kubernetes.io/instance=nginx-ingress,app.kubernetes.io/name=ingress-nginx
nginx-ingress-ingress-nginx-controller             LoadBalancer   10.43.10.136    192.168.178.240   80:31517/TCP,443:31733/TCP   28h   app.kubernetes.io/component=controller,app.kubernetes.io/instance=nginx-ingress,app.kubernetes.io/name=ingress-nginx

The guide describes it for dynDNS. How should I do this if I had two domains and two different websites. Is this done with a containerised certbot? Or do I need CNAME?

Upvotes: 0

Views: 341

Answers (1)

Harsh Manvar
Harsh Manvar

Reputation: 30120

You can run the command and check for the LoadBalancer IP which is external or exposed to internet IP.

you can this IP to DNS side as A record or CNAME record and you are done. Your both domain will be pointing the traffic to the Kubernetes cluster and inside the Kubernetes, you can create the ingress routes or record to divert the traffic to a specific service.

Upvotes: 1

Related Questions