Reputation: 6026
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?
Upvotes: 3
Views: 11283
Reputation: 100
There is an option that can configure your DNS provider automatically - you can install the External-DNS resource. No affiliation, I have simply found it useful.
You will need:
Install and Configure the External-DNS resource
External-DNS installed on your cluster will need to interact with your DNS provider. To configure External-DNS, you'll need to provide extra information regarding your DNS provider via a values.yaml file, as documented here.. First, you need to configure your DNS provider or take note of your DNS provider information. Then, with this information, you can deploy the External-DNS controller in your cluster passing the information via the values.yaml file. You will need to read the documentation of your DNS provider and External-DNS to know what information to provide and in what format, as External-DNS expects different keys and values for different providers. This is an example of how to install using Helm:
#values.yaml
---
provider: aws
aws:
secretAccessKey:
secretName: external-dns-aws-credentials
secretKey: aws_secret_access_key
accessKeyId:
secretName: external-dns-aws-credentials
secretKey: aws_access_key_id
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install external-dns bitnami/external-dns -f values.yaml --namespace external-dns --create-namespace
How to use External-DNS
Now that External-DNS is installed and configured, it will automatically create DNS records for Ingress and Service resources with the use of an annotation. For exmaple, to create an Ingress resource use the following annotation to automatically create a DNS record for the specified hostname:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
external-dns.alpha.kubernetes.io/hostname: my-app.example.com
spec:
rules:
- host: my-app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-service
port:
number: 80
Upvotes: 1
Reputation: 61669
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!
Upvotes: 6
Reputation: 492
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/
Upvotes: 0