How to Configure DNS for Applications Deployed on Kubernetes?

How to Configure DNS for Applications Deployed on Kubernetes

This post will help you with How to configure DNS for Applications deployed on Kubernetes. DNS configuration on Kubernetes is very important to make sure the applications can be accessed through DNS names. So the other part of resolution will be taken care by DNS or Domain Name System, because it is responsible for resolving domain names to IP addresses.

If you are interested in learning, Request you to go through the below recommended tutorial.

Prerequisites:

  • A Kubernetes cluster with one or more nodes.
  • kubectl command-line tool installed on your local machine.
Hope you have running Kubernetes cluster and kubectl is already installed on your local to manage your kubernetes cluster. if you dont have existing kubernetes cluster, please refer this link How to Install & Configure Kubernetes Cluster on CentOS 7 / RHEL 7 or How to Install & Configure Kubernetes Cluster on Ubuntu

Lets jump into the step by step instruction to configure DNS on Kubernetes cluster.

Step 1: Create Namespace on Kubernetes Cluster

I assume, you may have already a dedicated kubernetes namespace created for your application. If not, use kubectl command with namespace option to create namespace on kubernetes cluster for your application. Because, Kubernetes Namespace will help our application by organizing and isolating resources within Kubernetes cluster.

$ kubectl create namespace <namespace-name>

Replace <namespace-name> with your preferred name.

Step 2: Deploy Application on Kubernetes Cluster

I assume again, you already have application deployed on kubernetes cluster. If not, create deployment resource to deploy the application using the below command easily.

$ kubectl create deployment <deployment-name> --image=<image-name> --namespace=<namespace-name>

Replace <deployment-name> with the preferred name, <image-name> with the name of the Docker image that you need to deploy and <namespace-name> with the name of the namespace you created in Step 1.

Step 3: Expose Deployment

Once application is deployed and running in state, we need to expose the application. So users can access it from outside the kubernetes cluster. Use the below command to expose deployment.

$ kubectl expose deployment <deployment-name> --type=LoadBalancer --port=<port-number> --namespace=<namespace-name>

Replace <deployment-name> with the name of the deployment you created in Step 2, <port-number> with the port number your application is listening on and <namespace-name> with the name of the namespace you created in Step 1.

Step 4: Configure DNS

Here is the the final step to configure DNS for your application. You can use Kubernetes ingress to configure DNS as follows: Just create a kubernetes ingress yaml file and apply it.

Make sure the domain name record is created and mapped with correct CNAME record. 

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: <ingress-name>
namespace: <namespace-name>
spec:
rules:
- host: <domain-name>
http:
paths:
- backend:
serviceName: <service-name>
servicePort: <port-number>

Replace <ingress-name> with the name you want to give your ingress, <domain-name> with the domain name you want to use to access your application, <service-name> with the name of the service you created in Step 3 and <port-number> with the port number your application is listening on.

After configuring DNS, you should be able to access the application running on the kubernetes cluster using the domain name you specified in the ingress.

That's it for this post. Keep practicing and have fun. Leave your comments if any.

Related Searches and Questions asked:

  • Helm: List Installed Charts
  • Helm: Render Chart Templates Locally
  • Helm Upgrade: Update Chart Values with Examples
  • Kubectl: Force Delete Namespace Stuck in Terminating

  • إرسال تعليق

    0 تعليقات