본문 바로가기
Kubernetes/활용

쿠버네티스 DNS 기능 이해

by lumination 2024. 2. 22.

쿠버네티스

  • Core DNS
  • Local DNS

kubectl get pod -o wide -n kube-system

NAME                                  READY   STATUS    RESTARTS      AGE   IP             NODE           NOMINATED NODE   READINESS GATES
coredns-787d4945fb-dvd6h              1/1     Running   3 (16d ago)   73d   10.10.77.148   master-node    <none>           <none>
coredns-787d4945fb-smzwr              1/1     Running   3 (16d ago)   73d   10.10.77.149   master-node    <none>           <none>
etcd-master-node                      1/1     Running   1 (16d ago)   56d   192.168.0.27   master-node    <none>           <none>
kube-apiserver-master-node            1/1     Running   1 (16d ago)   56d   192.168.0.27   master-node    <none>           <none>
kube-controller-manager-master-node   1/1     Running   1 (16d ago)   56d   192.168.0.27   master-node    <none>           <none>
kube-proxy-2ggv4                      1/1     Running   2 (16d ago)   73d   192.168.0.62   worker-node1   <none>           <none>
kube-proxy-pjlsj                      1/1     Running   3 (16d ago)   73d   192.168.0.27   master-node    <none>           <none>
kube-scheduler-master-node            1/1     Running   1 (16d ago)   56d   192.168.0.27   master-node    <none>           <none>

위 내역을 보면 coredns가 있다. 

이중화를 위해 2개가 떠있다.

 

k get deploy -o wide -n kube-system

NAME      READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES                                   SELECTOR
coredns   2/2     2            2           73d   coredns      registry.k8s.io/coredns/coredns:v1.9.3   k8s-app=kube-dns

 

k describe deploy coredns -n kube-system

Name:                   coredns
Namespace:              kube-system
CreationTimestamp:      Mon, 11 Dec 2023 15:05:24 +0900
Labels:                 k8s-app=kube-dns
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               k8s-app=kube-dns
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  1 max unavailable, 25% max surge
Pod Template:
  Labels:           k8s-app=kube-dns
  Service Account:  coredns
  Containers:
   coredns:
    Image:       registry.k8s.io/coredns/coredns:v1.9.3
    Ports:       53/UDP, 53/TCP, 9153/TCP
    Host Ports:  0/UDP, 0/TCP, 0/TCP
    Args:
      -conf
      /etc/coredns/Corefile
    Limits:
      memory:  170Mi
    Requests:
      cpu:        100m
      memory:     70Mi
    Liveness:     http-get http://:8080/health delay=60s timeout=5s period=10s #success=1 #failure=5
    Readiness:    http-get http://:8181/ready delay=0s timeout=1s period=10s #success=1 #failure=3
    Environment:  <none>
    Mounts:
      /etc/coredns from config-volume (ro)
  Volumes:
   config-volume:
    Type:               ConfigMap (a volume populated by a ConfigMap)
    Name:               coredns
    Optional:           false
  Priority Class Name:  system-cluster-critical
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   coredns-787d4945fb (2/2 replicas created)
Events:          <none>
 nhn@AL01600616  ~/work

 

 

코어DNS는 이중화를 위해 2개의 파드가 디플로이먼트로 실행

로컬DNS는 쿠버네티스 전체 노드에 데몬셋으로 실행된다.

 * 데몬셋은 쿠버네티스가 실행되는 모든 노드에서 자동으로 실행하는 파드이다.

 

기존 클러스터에 노드가 추가되면 해당 노드에 데몬셋으로 등록된 파드가 자동으로 실행된다.

스토리지, 루깅, 모니터링 용도의 파드가 주로 데몬셋으로 실행된다.

 

https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/

 

로컬DNS 조회

kubectl get services -n=kube-system -o wide

NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE   SELECTOR
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   73d   k8s-app=kube-dns

 

kubectl exec -it busybox -- sh

/ # cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local openstacklocal
nameserver 10.96.0.10
options ndots:5

파드의 resolv 설정 ip가 kube-dns로 되어 있다.