- Published on
Expose a Kubernetes service on your own custom domain
- Author
- Written by Peter Jausovec
- Name Peter Jausovec
- @pjausovec
What do you need?
- Kubernetes cluster and access to it (i.e. so you can deploy stuff)
- Your application running in the Kubernetes cluster
- Registered domain name (I am using Name.com for my domains, but any other registrar works as well)
- Helm
Note
Note: I am using the word application to represent your code that runs in your cluster and you want to access it through the domain name. Your code is running inside of a Docker image and a Kubernetes pod that's part of a deployment and is exposed through a Kubernetes service. But application is what I'll use to refer to all this.
- Create an Ingress resource
- Deploy the Ingress controller
- Update the domain records to point to the clusters
Accessing Kubernetes from the outside
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: www.mycoolapp.mydomain.com
http:
paths:
- path: /
backend:
serviceName: mycoolapp
servicePort: 80
helm install stable/nginx-ingress
Note
Note that there are a plethora of buttons and knobs you can adjust and twist when deploying the controller — there's a whole list of them here.
kubectl get services --all-namespaces

*nginx-ingress-controller
service in the image above is what you need. This is the IP address you will point your domain to.kubectl get svc --all-namespaces -o jsonpath='{range .items[?(@.spec.type=="LoadBalancer")]}{.metadata.name}:{.status.loadBalancer.ingress[0].ip}{"\n"}{end}'
Pointing your domain to the cluster
A
and CNAME DNS
records to point your domain (host) to the cluster.
www.mycoolapp.mydomain.com
and as an answer, I entered my clusters IP address.CNAME
record and pointed mycoolapp.mydomain.com
to the cluster host name (usually, you can find this in your cloud providers settings). You don't have to provide a CNAME
, an A
record is enough. Note that if you don't provide the CNAME
, then mycoolapp.mydomain.com
will not resolve to your application!Test it out!
mycoolapp.mydomain.com
. Tadaaa — you should be able to get a response back (in my case, the application I deployed was a simple NGINX container, thus the default NGINX page)