Create your first DNS record on Azure

In this article:

This article is not to explain an enterprise solution for creating a network flow , however we will explain the steps of creating your first DNS record from A to Z.

Introduction

In today’s digital world, having a website or an application is crucial for businesses of all sizes. However, in order to make your website or application accessible to users, you need to map your domain name to the IP address of your server. This is where DNS (Domain Name System) comes into play. DNS allows you to associate your domain name with an IP address, making it easier for users to access your website or application. In this article, we will explore how to create a DNS record and map it to an Azure resource, using Azure DNS, Microsoft’s cloud-based DNS service. We will guide you through the process of creating a DNS zone, creating DNS records, and configuring your domain name to point to your Azure resources. By the end of this article, you will have a clear understanding of how to set up and configure DNS for your Azure resources, ensuring your website or application is easily accessible to your users.

Buy and map an App Service domain

For pricing information on App Service domains, visit the App Service Pricing page and scroll down to App Service Domain.

To create a DNS record , we need to follow the below steps.

  1. In the Azure portal, navigate to your “App Service Domains”.

2. In the left menu for your app, select Create.

3. Add your Domain name in the resource group that you have chosen and create the resource.

4. Once the resource is created , DNS zone will be created so let’s open it.

5. Here we will create our A record and map it to the IP address of our application Ingress hosted in Kubernetes.

kubectl get ingress -n <YOUR NAMESPACE>

We will add our custom subdomain name as “streamlit” that will be appended automatically to the domain that we have created and our Ingress IP address.

6. Once added , we can hit our DNS record on the browser and we will be routed to our application.

Difference between A record and CNAME record

Both A and CNAME are types of DNS (Domain Name System) records used to map a domain name to an IP address.

A record type is used to associate a domain name with an IPv4 address. When a user enters a domain name into a web browser, the browser queries the DNS server for the corresponding A record. If the A record is found, the DNS server returns the associated IP address, and the browser uses that IP address to establish a connection to the web server hosting the website.

CNAME (Canonical Name) record type, on the other hand, is used to create an alias for a domain name. It maps a domain name to another domain name instead of an IP address. When a DNS lookup is performed on a domain name with a CNAME record, the DNS server returns the corresponding canonical name instead of an IP address. The DNS resolver then uses the canonical name to perform a new DNS lookup to get the IP address of the target domain name.

For example, let’s say you have two domain names, www.example.com and blog.example.com, and both of them are hosted on the same server with the IP address 192.0.2.1. You can create an A record for each domain name to point to the IP address, or you can create a CNAME record for blog.example.com to point to www.example.com. When a user enters blog.example.com into their web browser, the DNS server returns the canonical name www.example.com, and the browser then performs a new DNS lookup for www.example.com to get the IP address.

Create kubernetes Manifests

We will create the ingress manifest and then we will implement the SSL/TLS security termination.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-app-ingress-streamlit
  namespace: streamlit
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt
    certmanager.k8s.io/acme-challenge-type: http01
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  tls:
  - hosts:
    - streamlit.avaxiahomelabs.com
    secretName: tls-secret
  rules:
  - host: streamlit.homelabs.com
    http:
      paths:
        - pathType: Prefix
          path: "/"
          backend:
            service:
              name: streamlit-hello-world
              port:
                number: 80

Now we will create the ClusterIssuer

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: "hassene.fliss25@gmail.com"
    privateKeySecretRef:
      name: letsencrypt
    solvers:
    - http01:
        ingress:
          class: nginx
          podTemplate:
            spec:
              nodeSelector:
                "kubernetes.io/os": linux

Finally , we will create the certificate.

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: streamlit-cert
  namespace: streamlit
spec:
  secretName: tls-secret
  dnsNames:
  - streamlit.homelabs.com #adress of your ingress controller 
  issuerRef:
    name: letsencrypt
    kind: ClusterIssuer

Once everything is done , we will now test our DNS and its security TLS/SSL termination.

Bingoooo….TLS/SSL and DSN record are working.

Conclusion

In conclusion, Azure DNS provides a powerful and easy-to-use solution for managing DNS records and mapping domain names to Azure resources. With Azure DNS, you can create and manage DNS zones, create DNS records, and configure your domain name to point to your Azure resources, all from a single interface. By following the steps outlined in this article, you can quickly and easily set up and configure DNS for your Azure resources, ensuring your website or application is easily accessible to your users. Whether you are a small business owner or a large enterprise, Azure DNS can help you streamline your DNS management and improve the performance and reliability of your website or application.