<commit_before>= Using CoreDNS for Service Discovery (WIP)

:toc:

This tutorial will show you how to update an existing Kubernetes cluster to use https://coredns.io/[coredns] instead of the default https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns[kube-dns] for service discovery.

== Pre-requisites

A 3 master nodes and 5 worker nodes cluster as explained at link:../cluster-install#multi-master-multi-node-multi-az-gossip-based-cluster[] is used for this chapter.

All configuration files for this chapter are in the `coredns` directory.

== Status Quo

In every fresh Kubernetes cluster we will find a service named kube-dns that forwards all dns requests to a pod responsible for handling dns requests.

This is what it looks like in a fresh `minikube`:

```
kubectl describe svc kube-dns -n kube-system
Name:			kube-dns
Namespace:		kube-system
Labels:			addonmanager.kubernetes.io/mode=Reconcile
			k8s-app=kube-dns
			kubernetes.io/name=KubeDNS
Annotations:		kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"Reconcile","k8s-app":"kube-dns","kubernet...
Selector:		k8s-app=kube-dns
Type:			ClusterIP
IP:			10.0.0.10
Port:			dns	53/UDP
Endpoints:		172.17.0.7:53
Port:			dns-tcp	53/TCP
Endpoints:		172.17.0.7:53
Session Affinity:	None
Events:			<none>
```

To validate that the current dns setup is working we first have to deploy a `busybox` pod: `kubectl create -f busybox.yaml`.

Lets resolve the `kubernetes` service in the `default` namespace:
```
kubectl exec -ti busybox -- nslookup kubernetes.default
Server:    10.0.0.10
Address 1: 10.0.0.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes.default
Address 1: 10.0.0.1 kubernetes.default.svc.cluster.local
```
From here we can see, that the `kube-dns` service answered our request and the `kubernetes` service can be found at `10.0.0.1` - this looks perfect!

As a last step lets look at the `resolv.conf`:
```
kubectl exec busybox cat /etc/resolv.conf
nameserver 10.0.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
```
As expected, we see that the nameserver IP corresponds to the IP of the `kube-dns` service. Additionally the search domains also reflect the expected kubernetes schema (get more  link:https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/[here])

Now that we validated the current setup, lets deploy coredns.

== Deploying coredns

The `coredns` deployment relies on information which is specific to you cluster: CIDR of kubernetes services and cluster domain.
For minikube, you can deploy `coredns` from a pre-generated yaml: `kubectl create -f coredns-minikube.yaml`<commit_msg>adding more details<commit_after>= Using CoreDNS for Service Discovery (WIP)

:toc:

This tutorial will show you how to update an existing Kubernetes cluster to use https://coredns.io/[coredns] instead of the default https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dns[kube-dns] for service discovery.

== Pre-requisites

A 3 master nodes and 5 worker nodes cluster as explained at link:../cluster-install#multi-master-multi-node-multi-az-gossip-based-cluster[] is used for this chapter.

All configuration files for this chapter are in the `coredns` directory.

== Status Quo

Each Kubernetes cluster has a service named `kube-dns` that forwards all DNS requests to the pod responsible for handling DNS requests. This service can be seen as:

	$ kubectl get svc -n kube-system
	NAME       TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)         AGE
	kube-dns   ClusterIP   172.16.31.10   <none>        53/UDP,53/TCP   8m

More details about the service can be found:

	$ kubectl describe svc kube-dns -n kube-system
	Name:              kube-dns
	Namespace:         kube-system
	Labels:            k8s-addon=kube-dns.addons.k8s.io
	                   k8s-app=kube-dns
	                   kubernetes.io/cluster-service=true
	                   kubernetes.io/name=KubeDNS
	Annotations:       kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-addon":"kube-dns.addons.k8s.io","k8s-app":"kube-dns","kubernetes.io/clu...
	Selector:          k8s-app=kube-dns
	Type:              ClusterIP
	IP:                172.16.31.10
	Port:              dns  53/UDP
	TargetPort:        53/UDP
	Endpoints:         172.16.31.10:53,192.168.3.11:53
	Port:              dns-tcp  53/TCP
	TargetPort:        53/TCP
	Endpoints:         172.16.31.10:53,192.168.3.11:53
	Session Affinity:  None
	Events:            <none>

To validate that the current DNS setup is working we first have to deploy a `busybox` pod: 

	$ kubectl create -f templates/busybox.yaml
	pod "busybox" created

Lets resolve the `kubernetes` service in the `default` namespace:

```
$ kubectl exec -ti busybox -- nslookup kubernetes.default
Server:    172.16.31.10
Address 1: 172.16.31.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes.default
Address 1: 172.16.58.3 kubernetes.default.svc.cluster.local
```

The output shows that the `kube-dns` service answered the request and the `kubernetes` service can be found at `100.64.01`.

Lets look at the `resolv.conf`:

	$ kubectl exec busybox cat /etc/resolv.conf
	nameserver 172.16.31.10
	search default.svc.cluster.local svc.cluster.local cluster.local eu-central-1.compute.internal
	options ndots:5

As expected, the nameserver IP corresponds to the IP of the `kube-dns` service. Additionally, the search domains also reflect the expected kubernetes schema (get more https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/[here]).

== Deploying coredns

The `coredns` deployment relies on information which is specific to you cluster: CIDR of kubernetes services and cluster domain. For minikube, you can deploy `coredns` from a pre-generated yaml: `kubectl create -f coredns-minikube.yaml`
{'fraction_non_alphanumeric': 0.10249122220364487, 'fraction_numerical': 0.032770439725798364, 'mean_word_length': 3.651632970451011, 'pattern_counts': {'":': 14, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 18, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5036207', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1936, 'n_words': 611}