Installing, configuring 3 node Kubernetes(master) cluster on CentOS 7.5 – Adding CoreDNS as part of the Kubernetes cluster
In Part 4 I described how to install and configure the kubernetes manifest and kubelet service, below we are going to add the newly addition CoreDNS to your Kubernetes cluster.
- Part 1: Initial setup – bear-metal installation, configuration
- Part 2: Installing the Kubernetes VM’s
- Part 3: Installing and configuring Flanneld, CNI plugin and Docker
- Part 4: Installing and configuring kubernetes manifest and kubelet service
- Part 5: Adding CoreDNS as part of the Kubernetes cluster
- Part 6: Adding / Configuring Kubernetes worker nodes
- Part 7: Enabling / Configuring RBAC, TLS Node bootstrapping
- Part 8: Installing / Configuring Helm, Prometheus, Alertmanager, Grafana and Elasticsearch
This is Part 5 – Adding CoreDNS as part of the Kubernetes cluster.
Adding configuring CoreDNS
Lets begin by downloading the latest CoreDNS version.
1 2 3 |
cd /var/tmp curl -o coredns_1.2.0_linux_amd64.tgz https://github.com/coredns/coredns/releases/download/v1.2.0/coredns_1.2.0_linux_amd64.tgz tar zxf coredns_1.2.0_linux_amd64.tgz |
Note: to get the latest release click here.
After extracting the gz file, you will find a deployment directory.
In the deployment we are mostly interested in the kubernetes
in the kubernetes directory you will find a deployment script and a yaml file.
You can use the deployment script deploy.sh somthink like the the below, or modify the yaml file your self and just run kubectl to deploy the config.
1 2 3 4 5 |
# deploy script ./deploy.sh -r 10.3.0.0/21 -r 10.20.0.0/20 -i 10.3.0.10 | kubectl apply -f - # OR run - kubectl apply.. kubectl apply -f coredns.yaml.sed |
Below is the coredns.yaml I have successfully used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
cat coredns.yaml apiVersion: v1 kind: ConfigMap metadata: name: coredns namespace: kube-system data: Corefile: | .:53 { errors log health kubernetes cluster.local 10.20.0.0/20 10.3.0.0/21 { upstream 8.8.8.8 8.8.4.4 pods insecure fallthrough } prometheus :9153 proxy . /etc/resolv.conf cache 30 cluster.local 10.20.0.0/20 10.3.0.0/21 reload loadbalance } --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: coredns namespace: kube-system labels: k8s-app: kube-dns kubernetes.io/name: "CoreDNS" spec: replicas: 2 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 selector: matchLabels: k8s-app: kube-dns template: metadata: labels: k8s-app: kube-dns spec: tolerations: - key: "CriticalAddonsOnly" operator: "Exists" containers: - name: coredns image: coredns/coredns:1.2.0 imagePullPolicy: IfNotPresent args: [ "-conf", "/etc/coredns/Corefile" ] volumeMounts: - name: config-volume mountPath: /etc/coredns readOnly: true ports: - containerPort: 53 name: dns protocol: UDP - containerPort: 53 name: dns-tcp protocol: TCP - containerPort: 9153 name: metrics protocol: TCP securityContext: allowPrivilegeEscalation: false capabilities: add: - NET_BIND_SERVICE drop: - all readOnlyRootFilesystem: true livenessProbe: httpGet: path: /health port: 8080 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 dnsPolicy: Default volumes: - name: config-volume configMap: name: coredns items: - key: Corefile path: Corefile --- apiVersion: v1 kind: Service metadata: name: kube-dns namespace: kube-system annotations: prometheus.io/port: "9153" prometheus.io/scrape: "true" labels: k8s-app: kube-dns kubernetes.io/cluster-service: "true" kubernetes.io/name: "CoreDNS" spec: selector: k8s-app: kube-dns clusterIP: 10.3.0.10 ports: - name: dns port: 53 protocol: UDP - name: dns-tcp port: 53 protocol: TCP |
Just run the below to apply and configure, this will launch 2 instances of CoreDNS.
1 |
kubectl apply -f coredns.yaml |
Below is the kubectl output of my cluster after adding CoreDNS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
kubectl get all --all-namespaces -o wide NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE kube-system pod/coredns-58c8c868b7-84d5q 1/1 Running 0 3d 10.20.2.31 kmaster2 kube-system pod/coredns-58c8c868b7-jkg4h 1/1 Running 0 3d 10.20.3.41 kmaster1 kube-system pod/kube-apiserver-kmaster1 1/1 Running 6 4d 172.20.0.11 kmaster1 kube-system pod/kube-apiserver-kmaster2 1/1 Running 9 7d 172.20.0.12 kmaster2 kube-system pod/kube-apiserver-kmaster3 1/1 Running 11 11d 172.20.0.13 kmaster3 kube-system pod/kube-controller-manager-kmaster1 1/1 Running 6 4d 172.20.0.11 kmaster1 kube-system pod/kube-controller-manager-kmaster2 1/1 Running 9 7d 172.20.0.12 kmaster2 kube-system pod/kube-controller-manager-kmaster3 1/1 Running 11 11d 172.20.0.13 kmaster3 kube-system pod/kube-proxy-kmaster1 1/1 Running 6 4d 172.20.0.11 kmaster1 kube-system pod/kube-proxy-kmaster2 1/1 Running 5 7d 172.20.0.12 kmaster2 kube-system pod/kube-proxy-kmaster3 1/1 Running 6 7d 172.20.0.13 kmaster3 kube-system pod/kube-scheduler-kmaster1 1/1 Running 6 4d 172.20.0.11 kmaster1 kube-system pod/kube-scheduler-kmaster2 1/1 Running 9 7d 172.20.0.12 kmaster2 kube-system pod/kube-scheduler-kmaster3 1/1 Running 11 11d 172.20.0.13 kmaster3 NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR default service/kubernetes ClusterIP 10.3.0.1 <none> 443/TCP 11d <none> kube-system service/kube-dns ClusterIP 10.3.0.10 <none> 53/UDP,53/TCP 3d k8s-app=kube-dns NAMESPACE NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR kube-system deployment.apps/coredns 2 2 2 2 3d coredns coredns/coredns:1.2.0 k8s-app=kube-dns NAMESPACE NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR kube-system replicaset.apps/coredns-58c8c868b7 2 2 2 3d coredns coredns/coredns:1.2.0 k8s-app=kube-dns,pod-template-hash=1474742463 |
To test DNS working you can do something like the below.
To see full dns logs run the below.
Note: logs are turned on for everything, you might wont to change that once configured.
1 2 3 4 |
kubectl -n kube-system log pod/coredns-58c8c868b7-jkg4h --follow & # After running the below dns tools example, output should look something like the below. 10.20.3.1:47126 - [14/Aug/2018:16:08:10 +0000] 5457 "AAAA IN kubernetes.default.svc.cluster.local. udp 54 false 512" NOERROR qr,aa,rd,ra 147 0.000114994s |
Next, lets start a pod called dnstools from infoblox, you do so by running the below.
Note: Infoblox has create a very good small image ready with all dns testing tools you might need.
1 2 3 4 5 6 7 8 |
kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools If you don't see a command prompt, try pressing enter. dnstools# nslookup kubernetes Server: 10.3.0.10 Address: 10.3.0.10#53 Name: kubernetes.default.svc.cluster.local Address: 10.3.0.1 |
Congratulations, you now have a working Kubernetes CoreDNS configured.
CoreDNS has great list of documents at the CoreDNS website, as well as a list available Plugins to extend feature functionality.
In Part 6 will continue Adding / Configuring Kubernetes worker nodes (coming soon).
You might also like – Other related articles to Docker and Kubernetes / micro-service.
Like what you’re reading? please provide feedback, any feedback is appreciated.
Leave a Reply