CKA SimA 16 CoreDNS 설정 변경

(CKA 1.32A - Q16 CoreDNS 설정 변경에서 넘어옴)

1 개요[ | ]

CoreDNS 설정에 커스텀 도메인 추가하기
  • cluster.local 외에 custom-domain 도메인에서도 서비스 이름이 해석되도록 CoreDNS 설정 변경
  • CoreDNS의 kubernetes 플러그인 블록을 수정하여 새로운 도메인 추가
  • 변경 전 설정 백업, 변경 적용 후 테스트, 문제가 있을 경우 복구까지 전 과정 포함
  • 관련문서: "custom dns" → https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/

2 설정 백업[ | ]

  • 설정 변경 전 기존 CoreDNS 설정 백업
# k -n kube-system get cm coredns -o yaml > /opt/course/16/coredns_backup.yaml

3 CoreDNS 설정 변경[ | ]

  • CoreDNS 설정(ConfigMap) 편집
# k -n kube-system edit cm coredns
  • kubernetes 플러그인 블록 수정 (기존 cluster.localcustom-domain 추가)
-    kubernetes cluster.local in-addr.arpa ip6.arpa {
+    kubernetes custom-domain cluster.local in-addr.arpa ip6.arpa {
  • 변경 예시 (Corefile 일부)
.:53 {
    errors
    health {
       lameduck 5s
    }
    ready
    kubernetes custom-domain cluster.local in-addr.arpa ip6.arpa {
       pods insecure
       fallthrough in-addr.arpa ip6.arpa
       ttl 30
    }
    prometheus :9153
    forward . /etc/resolv.conf {
       max_concurrent 1000
    }
    cache 30 {
       disable success cluster.local
       disable denial cluster.local
    }
    loop
    reload
    loadbalance
}

4 CoreDNS 재시작[ | ]

  • 변경된 ConfigMap이 반영되도록 CoreDNS Deployment 재시작
# k -n kube-system rollout restart deploy coredns
deployment.apps/coredns restarted

5 설정 테스트[ | ]

  • busybox:1 이미지로 테스트용 Pod 생성
# k run dns-checker --image=busybox:1 --command -- sleep 3600
pod/dns-checker created
  • Pod 내부 진입
# k exec -it dns-checker -- sh
/ #
  • DNS 해석 확인
/ # nslookup kubernetes.default.svc.cluster.local
Server:    10.96.0.10
Address 1: 10.96.0.10

Name:      kubernetes.default.svc.cluster.local
Address 1: 10.96.0.1
/ # nslookup kubernetes.default.svc.custom-domain
Server:    10.96.0.10
Address 1: 10.96.0.10

Name:      kubernetes.default.svc.custom-domain
Address 1: 10.96.0.1

6 설정 복구[ | ]

  • 변경사항 확인
# k diff -f /opt/course/16/coredns_backup.yaml
  • 기존 ConfigMap 삭제 후 백업 파일로 복구
# k -n kube-system delete cm coredns
configmap "coredns" deleted
# k apply -f /opt/course/16/coredns_backup.yaml
configmap/coredns created
  • CoreDNS 재시작
# k -n kube-system rollout restart deploy coredns
deployment.apps/coredns restarted

7 같이 보기[ | ]

8 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}