diff --git a/docs/09-Networking/20-CoreDNS-in-Kubernetes.md b/docs/09-Networking/20-CoreDNS-in-Kubernetes.md index 4f720480..9b76d3c9 100644 --- a/docs/09-Networking/20-CoreDNS-in-Kubernetes.md +++ b/docs/09-Networking/20-CoreDNS-in-Kubernetes.md @@ -1,152 +1,141 @@ -# CoreDNS in kubernetes +# CoreDNS in Kubernetes - Take me to [Lecture](https://kodekloud.com/courses/certified-kubernetes-administrator-with-practice-tests/lectures/9808285) + - Take me to [Lecture](https://kodekloud.com/courses/certified-kubernetes-administrator-with-practice-tests/lectures/9808285) - #### Solution +In this section, we will take a look at **CoreDNS in the Kubernetes** - 1. Check the Solution -
+## To view the Pod - ``` - CoreDNS - ``` -
- - 2. Check the Solution +``` +$ kubectl get pods -n kube-system +NAME READY STATUS RESTARTS AGE +coredns-66bff467f8-2vghh 1/1 Running 0 53m +coredns-66bff467f8-t5nzm 1/1 Running 0 53m +``` -
+## To view the Deployment - ``` - 2 - ``` -
+``` +$ kubectl get deployment -n kube-system +NAME READY UP-TO-DATE AVAILABLE AGE +coredns 2/2 2 2 53m +``` - 3. Check the Solution +## To view the configmap of CoreDNS -
+``` +$ kubectl get configmap -n kube-system +NAME DATA AGE +coredns 1 52m +``` - ``` - 10.96.0.10 - ``` -
+## CoreDNS Configuration File - 4. Check the Solution +``` +$ kubectl describe cm coredns -n kube-system -
+Corefile: +--- +.:53 { + errors + health { lameduck 5s + } + ready + kubernetes cluster.local in-addr.arpa ip6.arpa { + pods insecure + fallthrough in-addr.arpa ip6.arpa + ttl 30 + } + prometheus :9153 + forward . /etc/resolv.conf + cache 30 + loop + reload +} +``` - ``` - /etc/coredns/Corefile +## To view the Service - OR +``` +$ kubectl get service -n kube-system +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +kube-dns ClusterIP 10.96.0.10 53/UDP,53/TCP,9153/TCP 62m +``` - kubectl -n kube-system describe deployments.apps coredns | grep -A2 Args | grep Corefile - ``` -
+## To view Configuration into the kubelet - 5. Check the Solution +``` +$ cat /var/lib/kubelet/config.yaml | grep -A2 clusterDNS +clusterDNS: +- 10.96.0.10 +clusterDomain: cluster.local -
+``` - ``` - Configured as a ConfigMapObject - ``` -
+## To view the fully qualified domain name - 6. Check the Solution +- With the `host` command, we will get fully qualified domain name (FQDN). -
+``` +$ host web-service +web-service.default.svc.cluster.local has address 10.106.112.101 - ``` - CoreDNS - ``` -
+$ host web-service.default +web-service.default.svc.cluster.local has address 10.106.112.101 - 7. Check the Solution +$ host web-service.default.svc +web-service.default.svc.cluster.local has address 10.106.112.101 -
+$ host web-service.default.svc.cluster.local +web-service.default.svc.cluster.local has address 10.106.112.101 +``` - ``` - coredns - ``` -
+## To view the `/etc/resolv.conf` file - 8. Check the Solution +``` +$ kubectl run -it --rm --restart=Never test-pod --image=busybox -- cat /etc/resolv.conf +nameserver 10.96.0.10 +search default.svc.cluster.local svc.cluster.local cluster.local +options ndots:5 +pod "test-pod" deleted +``` -
+## Resolve the Pod - ``` - cluster.local - ``` -
+``` +$ kubectl get pods -o wide +NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES +test-pod 1/1 Running 0 11m 10.244.1.3 node01 +nginx 1/1 Running 0 10m 10.244.1.4 node01 - 9. Check the Solution +$ kubectl exec -it test-pod -- nslookup 10-244-1-4.default.pod.cluster.local +Server: 10.96.0.10 +Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local -
+Name: 10-244-1-4.default.pod.cluster.local +Address 1: 10.244.1.4 +``` - ``` - Ok - ``` -
+## Resolve the Service - 10. Check the Solution +``` +$ kubectl get service +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +kubernetes ClusterIP 10.96.0.1 443/TCP 85m +web-service ClusterIP 10.106.112.101 80/TCP 9m -
+$ kubectl exec -it test-pod -- nslookup web-service.default.svc.cluster.local +Server: 10.96.0.10 +Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local - ``` - web-service - ``` -
+Name: web-service.default.svc.cluster.local +Address 1: 10.106.112.101 web-service.default.svc.cluster.local - 11. Check the Solution +``` -
- - ``` - web-serivce.default.pod - ``` -
- 12. Check the Solution +#### References Docs -
- - ``` - web-service.payroll - ``` -
- - 13. Check the Solution - -
- - ``` - web-service.payroll.svc.cluster - ``` -
- - 14. Check the Solution - -
- - ``` - kubectl edit deploy webapp - - Search for DB_Host and Change the DB_Host from mysql to mysql.payroll - - spec: - containers: - - env: - - name: DB_Host - value: mysql.payroll - ``` -
- - 15. Check the Solution - -
- - ``` - kubectl exec -it hr nslookup mysql.payroll > /root/nslookup.out - ``` -
\ No newline at end of file +- https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services +- https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pods