AWS EKS POD DNS 문제 해결 - CoreDNS forward

2023. 9. 13. 14:20Dev/EKS

728x90

nslookup kubernetes.default 10.100.0.10

server can't find kubernetes.default: NXDOMAIN

 

개발팀에서 새로운 기능을 추가해서 배포를 했는데 

I/O error on POST request for “https://messages.dev.example.com/email/v2/messages”: No subject alternative DNS name matching messages.dev.example.com found.

이런 에러가 발생한다고 문의가 왔습니다.

로그를 상세히 찍어봐도 에러 메시지는 비슷했습니다.

No subject alternative DNS name matching messages.dev.example.com found

 

해당 도메인을 관리하는 Route53에 들어가 봐도 설정 잘 되어있었습니다.

도메인이 가르키는 곳은 다른 AWS 계정의 API GW 서비스의 주소였습니다.

로컬에서 curl 날려봐도 권한에러를 내면서 통신은 되는 것을 확인했습니다.

messages.dev.example.com	canonical name = d-1234567890.execute-api.ap-northeast-2.amazonaws.com.
Name:	d-1234567890.execute-api.ap-northeast-2.amazonaws.com
Address: 15.164.--.--
Name:	d-1234567890.execute-api.ap-northeast-2.amazonaws.com
Address: 15.165.--.--
다른 계정 eks에서 확인하면 이런 주소로가는데
 
문제가 있는 EKS에서는 아래처럼 192.168로 찾아갑니다.
nslookup messages.dev.example.com
Server:		10.100.0.10
Address:	10.100.0.10#53

Non-authoritative answer:
messages.dev.example.com	canonical name = d-1234567890.execute-api.ap-northeast-2.amazonaws.com.
Name:	d-1234567890.execute-api.ap-northeast-2.amazonaws.com
Address: 192.168.150.--
Name:	d-1234567890.execute-api.ap-northeast-2.amazonaws.com
Address: 192.168.119.--
Name:	d-1234567890.execute-api.ap-northeast-2.amazonaws.com
Address: 192.168.139.--

 

---

aws 지식센터 문서를 보고 해결을 시도했다.

https://repost.aws/ko/knowledge-center/eks-dns-failure

 

Amazon EKS 관련 DNS 오류 문제 해결

Amazon Elastic Kubernetes Service(Amazon EKS) 클러스터에서 CoreDNS를 사용하는 애플리케이션 또는 포드가 내부 또는 외부 DNS 이름 확인에 실패합니다.

repost.aws

 

 

1. CoreDNS 확인

kubectl get service kube-dns -n kube-system
kubectl -n kube-system get endpoints kube-dns
NAME       ENDPOINTS                                                        AGE
kube-dns   192.168.2.218:53,192.168.3.117:53,192.168.2.218:53 + 1 more...   90d

 

참고: 엔드포인트 목록이 비어 있는 경우 CoreDNS 포드의 포드 상태를 확인하세요.

-> CoreDNS는 문제 없는것같다.

3.    CoreDNS와 통신할 때 보안 그룹 또는 네트워크 액세스 제어 목록(네트워크 ACL)이 포드를 차단하고 있지 않은지 확인합니다.

자세한 내용은 Amazon EKS에서 다른 포드에 내 포드가 연결되지 않는 이유는 무엇입니까?를 참조하세요.

 

-> 보안그룹을 올오픈으로 변경하고 테스트했지만 문제는 그대로였다.

 

1.    애플리케이션 포드 내에서 명령을 실행하려면 다음 명령을 실행하여 실행 중인 포드 내의 셸에 액세스 합니다.

$ kubectl exec -it your-pod-name -- sh

애플리케이션 포드에 사용 가능한 셸 바이너리가 없는 경우, 다음과 유사한 오류가 발생합니다.

OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"sh\": executable file not found in $PATH": unknown
command terminated with exit code 126

디버깅하려면 매니페스트 파일에 사용된 이미지를 busybox 이미지(Docker 웹 사이트)와 같은 다른 이미지로 업데이트합니다.

-> https://github.com/kubernetes/kubernetes/issues/66924

busybox 특정 버전에서 비슷한 에러가 발생한다는 이슈를 확인했다. (나랑 상관없음)

k debug <pod-name> -n <namespace> -it --image=arunvelsriram/utils

나는 이 이미지를 사용해서 테스트했다.

 

2.    kube-dns 서비스의 클러스터 IP가 포드의 /etc/resolv.conf에 있는지 확인하려면 포드 내부의 셸에서 다음 명령을 실행합니다.

cat /etc/resolv.conf

다음 예시 resolv.conf는 DNS 요청에 대해 10.100.0.10을 향하도록 구성된 포드를 보여 줍니다. IP는 kube-dns 서비스의 ClusterIP와 일치해야 합니다.

nameserver 10.100.0.10
search default.svc.cluster.local svc.cluster.local cluster.local ec2.internal
options ndots:5

-> 이 부분은 비슷하게 잘 나왔다.

 

3.    포드가 기본 ClusterIP를 사용하여 내부 도메인을 확인할 수 있는지 확인하려면 포드 내부의 셸에서 다음 명령을 실행합니다.

nslookup kubernetes.default 10.100.0.10

출력:

Server:     10.100.0.10
Address:    10.100.0.10#53
Name:       kubernetes.default.svc.cluster.local
Address:    10.100.0.1

 

-> 이 부분이 문서와 달라서 스샷을 찍어 커뮤니티에 질문했다.

서비스 생성 전에 생성된 파드는 호스트를 못 찾을 수 있다고 하셔서
디플로이먼트 자체를 새로 배포해 봤지만 문제는 그대로였다.

tcpdump나 ndots 변경, telnet으로 포트 확인, outbound정책 확인 등 방법을 주셨지만 해결이 안 되었다.

 

그러다가 팀원분께서 비슷한 에러를 겪고 해결한 적이 있다고 하셔서 (이유는 알 수 없고) 해보았는데 해결되었다.

 

해결 방법은 Coredns의 forward 설정을 변경하는 것이었다.

coredns의 configmap을 확인하고

/etc/resolv.conf 를 1.1.1.1로 수정하였다.

 k describe cm coredns -n kube-system
Name:         coredns
Namespace:    kube-system
Labels:       eks.amazonaws.com/component=coredns
              k8s-app=kube-dns
Annotations:  <none>

Data
====
Corefile:
----
.:53 {
    log
    errors
    health
    kubernetes cluster.local in-addr.arpa ip6.arpa {
      pods insecure
      fallthrough in-addr.arpa ip6.arpa
    }
    prometheus :9153
    # forward . /etc/resolv.conf
    forward . 1.1.1.1
    cache 30
    loop
    reload
    loadbalance
}

 

이 해결법은 아래 레딧에서 발견하셨다고 했다. (어떻게 찾으신걸까...)

https://www.reddit.com/r/kubernetes/comments/wzn561/dns_lookups_from_pod_fail_i_think_pods_cant_talk/

 

From the kubernetes community on Reddit

Explore this post and more from the kubernetes community

www.reddit.com

 

대충 읽어보면 이유는 알 수 없지만

원인은 서로 다른 파드들이 서로 통신하려고 하는 게 아니냐는 추측 정도?

 

kubectl rollout restart deploy coredns -n kube-system 를 하고 

외부로 호출이 안되던 문제는 해결이 됩니다.

 

그런데 다 끝난 줄 알았지만 멀쩡하던 다른 애플리케이션에서 에러가 발생합니다.

CoreDNS의 forward 설정을 바꾸는 것은 외부 DNS 서버를 이용하는 것이므로

AWS 리소스 내부 호출에서 문제가 생긴 것입니다.

 

진짜 문제의 원인과 해결 방법은 다음 편에서...

https://nauco.tistory.com/127

 

AWS EKS POD DNS 문제 해결 - Route53 CNAME/A record

지난 편에 이어서 AWS EKS CoreDNS의 configmap을 수정해서 forward의 값을 1.1.1.1로 변경시키는 것은 퍼블릭 도메인에는 효과가 있었습니다. 하지만 프라이빗 도메인으로 연결해 놓은 AWS 내부 리소스를

nauco.tistory.com

 

 

728x90