DevTech101

DevTech101
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...

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. This is Part 5 – Adding CoreDNS as part of the Kubernetes cluster.

Adding configuring CoreDNS

Lets begin by downloading the latest CoreDNS version.
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.
# 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.
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.
kubectl apply -f coredns.yaml
Below is the kubectl output of my cluster after adding CoreDNS.
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             443/TCP         11d       
kube-system   service/kube-dns     ClusterIP   10.3.0.10            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.
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.
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.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: