Question

Accessing a service using my own domain, without setting the ip in the nameserver

Posted January 3, 2020 444 views
VPNKubernetes

I have a grafana dashboard, an nginx-ingress and an OpenVPN service running in my cluster just fine, and I am able to reach everything I need using the cluster IP, but I want to use a domain name, lets say grafana.my-domain.com. How can I achieve this?

This might be some usefull information:

My grafana service:

▶ k get svc --namespace monitoring
NAME                                               TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
doks-cluster-monitoring-grafana                    ClusterIP   10.245.162.148   <none>        80/TCP                       120m

My OpenVPN service:

▶ k get svc --namespace access    
NAME      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
openvpn   ClusterIP   10.245.122.233   <none>        1194/TCP   56m

My nginx-ingress:

▶ k get svc --namespace nginx-ingress
NAME                               TYPE           CLUSTER-IP       EXTERNAL-IP       PORT(S)                                     AGE
nginx-ingress-controller           LoadBalancer   10.245.199.175   xxx.xxx.xxx.xxx   80:31883/TCP,443:32254/TCP,1194:32021/TCP   48m
nginx-ingress-controller-metrics   ClusterIP      10.245.185.36    <none>            9913/TCP                                    48m
nginx-ingress-default-backend      ClusterIP      10.245.242.220   <none>            80/TCP                                      48m

My CoreDNS:

▶ k get svc --namespace kube-system  
NAME                                                 TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)                  AGE
kube-dns                                             ClusterIP   10.245.0.10   <none>        53/UDP,53/TCP,9153/TCP   143m

My /etc/resolv.conf:

▶ cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 10.245.0.10
nameserver 192.168.1.1

My CoreDNS configmap:

▶ k describe cm --namespace kube-system coredns       
Name:         coredns
Namespace:    kube-system
Labels:       <none>
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"v1","data":{"Corefile":".:53 {\n    errors\n    health\n    ready\n    kubernetes cluster.local in-addr.arpa ip6.arpa {\n  ...

Data
====
Corefile:
----
.:53 {
    errors
    health
    ready
    kubernetes cluster.local in-addr.arpa ip6.arpa {
      pods insecure
      fallthrough in-addr.arpa ip6.arpa
    }
    prometheus :9153
    forward . /etc/resolv.conf
    cache 30
    loop
    reload
    loadbalance
}

Events:  <none>

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Do you want this to just work locally on your machine? or globally?
If locally, You could setup an /etc/hosts entry on your machine to manually resolve your hostname to the IP of the LB. Then configure ingress rules to route based on that hostname.
If globally, do you already own your domain?
If so, you would configure your domain’s DNS to resolve to the IP of the Loadbalancer, then ensure you have an ingress rule to appropriately route to your service based on the hostname you have chosen.

Submit an Answer