Earlier we used to edit the coredns configmap and put the hostfile entries there. But whenever there was a server restart it was lost and had to be redone. Also if we make any mistakes while editing the default configmap, it will result in the coredns not working. Later we discovered that coredns allows us to add customization as a separate configmap named coredns-custom in the namespace kube-system.
Below are the steps:
In the master node create hostfile-cm.yaml file and add the below content
apiVersion: v1 |
Apply the configuration
kubectl apply -f hostfile-cm.yaml |
Get the pod name of coredns
kubectl -n kube-system get po |
Delete the pod so that the coredns deployment recreates it with loading the coredns-custom configmap in the process.
kubectl -n kube-system delete po <coredns-pod-name> |
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 |
Then try pinging the domain names
If ping is not there then install it using the below commands
apt update |
apt install -y iputils-ping |