I deploy an ingress with app1
and app2
.
example.com/app1 ---> app1
example.com/app2 ---> app2
And define /etc/hosts in all the machine.
192.168.1.10 example.com
But i want to know in operation how can i use DNS and ingress.
What should i do? What ingress bring to me? I confused by ingress. How should i use it in practical envinroment?
I deployed a set of 10 or 12 services on K8s and needed a way to expose them to a mobile client. I could create a service of the type loadBalancer for each service, but it would requires to have 10 or more loadBalancers on AWS, all of them pointing to the same set of machines. Instead of that, It was created just one service of type loadBalancer, the ingress service, which depending of the path redirects to the appropriate service. The ingress is used for access outside the cluster, inside you can access using the cluster DNS. For example: my-svc.my-namespace.svc.cluster.local.
Check this link: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
And also this one: https://kubernetes.io/docs/concepts/services-networking/ingress/
With DNS you can't just use example.com
(example.com
is owned by IANA). You have to own the DNS configured on your ingress. For example:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: simple-fanout-example
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: mydomain.com
http:
paths:
- path: /foo
backend:
serviceName: service1
servicePort: 4200
In the case above you have to own mydomain.com
. You can buy your domain at any major domain registrar like GoDaddy.
Then you will have to expose your Ingress externally depending on the setup you have (AWS, bare-metal, etc) with a LoadBalancer Kubernetes Service and have an A, or CNAME entry on your domain registrar manager, point to that external endpoint (for mydomain.com
). For example, on AWS that entry would be a CNAME that looks like this: xxxxx-xxxxxxxxxxxx.us-west-2.elb.amazonaws.com
Note: You can ignore the host altogether but the ingress will only service a default backend as described here with a minimal ingress resource. As far as using your own DNS server, just you can too, as long as your DNS server correctly resolves mydomain.com to the external IP that your ingress controller is fronting.
Hope it helps!