Adding CoreDNS entry in K3s

CoreDNS is a flexible, extensible DNS server that can serve as the Kubernetes cluster DNS.
When ever the server restart or new dns entry needs to be done for the kubernetes cluster follow the below steps:


  1. In the master node create hostfile-cm.yaml file and add the below content.

Bangalore

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns-custom
  namespace: kube-system
data:
  test.server: |
saarthi.ai:53 {
  errors
  hosts {
    172.16.18.18            prod.saarthi.ai
    172.16.18.19            audiosvr.saarthi.ai
    103.155.115.194      prod-amd-dialer.saarthi.ai
    103.155.115.194      prod-rec-ahmd.saarthi.ai
    203.193.141.147      prod-mlr-dialer.saarthi.ai
    172.16.18.18           nats.saarthi.ai
  }
  reload
  loadbalance
}

Gujarat

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns-custom
  namespace: kube-system
data:
  test.server: |
saarthi.ai:53 {
  errors
  hosts {
    192.168.1.11      audiosvr.saarthi.ai
    192.168.1.12      audiosvr.saarthi.ai
    103.64.128.52   prod.saarthi.ai
    192.168.1.18      nats.saarthi.ai
  }
  reload
  loadbalance
}

   

Mangalore

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns-custom
  namespace: kube-system
data:
  test.server: |
saarthi.ai:53 {
  errors
  hosts {

    10.10.22.115      nats.saarthi.ai
    103.64.128.52   prod.saarthi.ai
    10.10.22.119      audiosvr.saarthi.ai
  }
  reload
  loadbalance
}

 

  1. Apply the configuration.

kubectl apply -f hostfile-cm.yaml


  1. Get the pod name of coredns.

kubectl -n kube-system get po


  1. Delete the pod so that the coredns deployment recreates it by loading the coredns-custom configmap in the process.

kubectl -n kube-system delete po <coredns-pod-name>


  1. Execute the below command to ssh into any pod other than coredns pod.

kubectl -n kube-system exec --stdin --tty <traefik_pod_name> -- /bin/sh


  1. Then try pinging the domain names.


  1. If ping is not there then install it using the below commands.

apt update


apt install -y iputils-ping