brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Feb 21. 2023

12. 오라클 클라우드 - 쿠버네티스 -DNS



<1> 쿠버네티스 DNS

<2>  core dns  테스트

<3> 서비스 디스커버리


<1> 쿠버네티스 DNS


1

질의 서 ?


내부에서 질의하여 확인한다.

내부에서 레코드가 없으면?   호스트 노드에  resolv.conf  에  dns 로  질의 한다.

예) 100.64.0.10에게 도메인 질의한다. 클러스터에 질의를 하는 것이다. = service/kube-dns   ClusterIP   100.64.0.10


요약

pod는 coredns에 질의를 보내고 응답받음.

codedns cluser ip에 질의를 보냄 =  resolv.conf  dns



2

Core DNS 는 DNS 서비스를 제공한다.

디플로이먼트로 배포 되어 있다.

core dns pod 가 존재한다.

서비스로 연결 되어 있다.

엔드포인트가 있다.



3

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get deploy,pod,svc,ep -n kube-system -l k8s-app=kube-dns -o wide

NAME  READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES          SELECTOR

deployment.apps/coredns   1/2     2            1           7d    coredns      ap-seoul-1.ocir.io/axoxdievda5j/oke-public-coredns@sha256:29455733e390fccfdbc5475f79fbb837b881278d641a6c58f6e7ae98687c6a46   k8s-app=kube-dns


NAME                          READY   STATUS    RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES

pod/coredns-d95cc75c9-l2gqf   1/1     Running   0          3d17h   10.244.0.138   10.0.10.141   <none>           <none>

pod/coredns-d95cc75c9-qkdt7   0/1     Running   0          7m1s    10.244.0.68    10.0.10.80    <none>           <none>


NAME               TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE   SELECTOR

service/kube-dns   ClusterIP   10.96.5.5    <none>        53/UDP,53/TCP,9153/TCP   7d    k8s-app=kube-dns


NAME                 ENDPOINTS                                           AGE

endpoints/kube-dns   10.244.0.138:53,10.244.0.138:53,10.244.0.138:9153   7d



4

coredns 는 pod가 2개 있다.


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get deployments.apps -n kube-system

NAME                  READY   UP-TO-DATE   AVAILABLE   AGE

coredns               2/2     2            2           7d

kube-dns-autoscaler   1/1     1            1           7d



5

파드를 자세히 보면

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pod -n kube-system -o wide -l k8s-app=kube-dns

NAME                      READY   STATUS    RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES

coredns-d95cc75c9-7wjqt   1/1     Running   0          3d17h   10.244.0.14    10.0.10.80    <none>           <none>

coredns-d95cc75c9-l2gqf   1/1     Running   0          3d17h   10.244.0.138   10.0.10.141   <none>           <none>


6

서비스를 보면

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get svc -n kube-system kube-dns

NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE

kube-dns   ClusterIP   10.96.5.5    <none>        53/UDP,53/TCP,9153/TCP   7d


7

configmaps 확인


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl describe configmaps -n kube-system coredns

Name:         coredns

Namespace:    kube-system

Labels:       <none>

Annotations:  <none>

Data

====

Corefile:

----

.:53 {

  errors

  health {

    lameduck 5s

  }

  ready

  kubernetes cluster.local in-addr.arpa ip6.arpa {

    pods insecure

    fallthrough in-addr.arpa ip6.arpa

  }

  prometheus :9153

  forward . /etc/resolv.conf

  cache 30

  loop

  reload

  loadbalance

}

import custom/*.server

BinaryData

====

Events:  <none>


6

동작 확인 ?

내부에서 질의하여 확인

내부에서 레코드가 없으면?   호스트 노드에  resolv.conf  에  dns 로  질의 한다.





<2>  core dns  테스트


1

Pod 를 만들어 dns   질의해 확인해보자.


2

coredns pod 를  1개로 줄여서 테스트하자


3

Coredns 2개

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pod -n kube-system -l k8s-app=kube-dns

NAME                      READY   STATUS    RESTARTS   AGE

coredns-d95cc75c9-7wjqt   1/1     Running   0          3d17h

coredns-d95cc75c9-l2gqf   1/1     Running   0          3d17h


4

Core dns 1개로 줄임

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl scale deployment -n kube-system coredns --replicas=1

Warning: spec.template.spec.nodeSelector[beta.kubernetes.io/os]: deprecated since v1.14; use "kubernetes.io/os" instead

deployment.apps/coredns scaled



topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pod -n kube-system -l k8s-app=kube-dns

NAME                      READY   STATUS    RESTARTS   AGE

coredns-d95cc75c9-l2gqf   1/1     Running   0          3d17h

coredns-d95cc75c9-qkdt7   0/1     Running   0          16s



5

파드 만들고

파드로 들어가 확인

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl run -it --rm netdebug --image=nicolaka/netshoot --restart=Never -- zsh

If you don't see a command prompt, try pressing enter.

netdebug#

#    

                                                                                                                                                                                                                                                                      


6

netdebug# cat /etc/resolv.conf

search default.svc.cluster.local svc.cluster.local cluster.local cluster1.oraclevcn.com sub31db2bea9.cluster1.oraclevcn.com

nameserver 10.96.5.5

options ndots:5

#

// CLUSTER-IP  =  10.96.5.5                                                                                                                                                                                                                                                  netdebug# exit

7

kubectl delete deploy,svc,pod --all




<3> 서비스 디스커버리


Service Discovery

CoreDNS 는 서비스에 대해  A레코더를 생성한다.

서비스를 도메인으로 어떻게 접근하는지 확인해 보자.


1

현재 확인


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get svc,pods,deploy,ep

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE

service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   2m42s

NAME                       ENDPOINTS   AGE

endpoints/oracle.com-oci   <none>      13h



2

topasvga@cloudshell:~ (ap-seoul-1)$ cat << EOF > svc-pod.yaml

> apiVersion: apps/v1

> kind: Deployment

> metadata:

>   name: deploy-cndk

> spec:

>   replicas: 3

>   selector:

>     matchLabels:

>       app: deploy-websrv

>   template:

>     metadata:

>       labels:

>         app: deploy-websrv

>     spec:

>       containers:

>       - name: cndk-websrv

>         image: gcr.io/google-samples/kubernetes-bootcamp:v1

>         ports:

>         - containerPort: 8080

> ---

> apiVersion: v1

> kind: Service

> metadata:

>   name: svc-clusterip

> spec:

>   ports:

>     - name: svc-webport

>       port: 9000

>       targetPort: 8080

>   selector:

>     app: deploy-websrv

>   type: ClusterIP

> EOF



3

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl apply -f svc-pod.yaml

deployment.apps/deploy-cndk created

service/svc-clusterip created


4

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get svc

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE

kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP    8m1s

svc-clusterip   ClusterIP   10.96.181.152   <none>        9000/TCP   9s


5

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get endpoints

NAME             ENDPOINTS                                             AGE

oracle.com-oci   <none>                                                13h

svc-clusterip    10.244.0.171:8080,10.244.0.70:8080,10.244.0.71:8080   28s


6

pod 생성, 연결해 확인하자.

topasvga@cloudshell:~ (ap-seoul-1)$ kubectl run -it --rm netdebug --image=nicolaka/netshoot --restart=Never -- zsh

If you don't see a command prompt, try pressing enter.

netdebug#

#                        

    

netdebug# nslookup svc-clusterip

Server:         10.96.5.5

Address:        10.96.5.5#53

** server can't find svc-clusterip: NXDOMAIN

#
// 인터넷이 되는 환경에서는 동작함.  여기는 cloudshell 로 인터넷이 안되는 환경이라 안됨.                                                                                                                                                                  netdebug# curl -s svc-clusterip:9000

#

// 인터넷이 되는 환경에서는 동작함.  여기는 cloudshell 로 인터넷이 안되는 환경이라 안됨.                                                                                                                                                                netdebug# exit


7

삭제

kubectl delete deploy,svc --all


감사합니다.

브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari