[Azure/Spring] 같은 클러스터 내 Pod 통신 이슈
현재 아키텍쳐 구조도
대부분의 CI/CD 파이프라인과 Azure 리소스 자원이 찍힌 상태로 아키텍쳐는 위와 같다. 위 구조로 서비스를 배포하고 서비스에 접속하니 하나의 에러와 마주쳤다.
Front ↔ Backend 통신 에러
FrontEnd(Vue.js)와 BackEnd(Spring Boot)를 별도의 pod으로 기동 시키고 FrontEnd의 External-IP
를 기반으로 웹 서비스에 접속하면 아래와 같이 Axios 에러가 발생한다.
같은 클러스터내의 pod끼리 통신이 불가능하다고 추측
이슈 해결 히스토리
Pod → Pod으로 접속 테스트
Front Pod에 직접 접속하여 curl
을 하용해 Backend Pod으로 요청을 보내보았다.
1
kubectl exec -it journeyjinni-frontend-77d48b7dcf-k8mlv -- /bin/bash
front pod에서 backend pod으로 정상 호출 확인이 되었다.
이런 경우 AP 영역에서 이슈가 있음을 확인
service의 endpoint 및 IP 확인
1
2
3
4
unggu556 [ ~ ]$ kubectl get svc -n journeyjinni
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
journeyjinni-backend LoadBalancer 10.0.207.61 57.155.17.41 80:32358/TCP 42d
journeyjinni-frontend LoadBalancer 10.0.239.50 20.247.236.103 80:30918/TCP 13d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
unggu556 [ ~ ]$ kubectl describe services journeyjinni-backend -n journeyjinni
Name: journeyjinni-backend
Namespace: journeyjinni
Labels: app=journeyjinni-backend
argocd.argoproj.io/instance=backend
chart=journeyjinni-backend-1.0.0
release=journeyjinni-backend-dev
Annotations: <none>
Selector: app=journeyjinni-backend
Type: Cluster-IP
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.0.207.61
IPs: 10.0.207.61
LoadBalancer Ingress: 57.155.17.41 (VIP)
Port: http 80/TCP
TargetPort: 8080/TCP
NodePort: http 32358/TCP
Endpoints: 10.244.0.82:8080
Session Affinity: None
External Traffic Policy: Cluster
Internal Traffic Policy: Cluster
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
unggu556 [ ~ ]$ kubectl describe services journeyjinni-frontend -n journeyjinni
Name: journeyjinni-frontend
Namespace: journeyjinni
Labels: app=journeyjinni-frontend
argocd.argoproj.io/instance=frontend
chart=journeyjinni-frontend-1.0.0
release=journeyjinni-frontend-dev
Annotations: <none>
Selector: app=journeyjinni-frontend
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.0.239.50
IPs: 10.0.239.50
LoadBalancer Ingress: 20.247.236.103 (VIP)
Port: http 80/TCP
TargetPort: 5173/TCP
NodePort: http 30918/TCP
Endpoints: 10.244.0.46:5173
Session Affinity: None
External Traffic Policy: Cluster
Internal Traffic Policy: Cluster
Events: <none>
Pod끼리 통신을 해야한다면 Type
이 LoadBalancer
가 아닌 Cluster
로 하는게 옳은 방법이라 하여 BackEnd Pod의 통신 방식을 다시 Cluster
방식으로 변경하였다.
FrontEnd Pod dns 정책확인 (정상)
1
2
kubectl get pod journeyjinni-frontend-776f78498-k8mnf -n journeyjinni -o
yaml | grep dnsPolicy
네트워크 네임스페이스 확인
1
kubectl get pod journeyjinni-frontend-776f78498-k8mnf -n journeyjinni -o yaml | grep hostNetwork
BackEnd 호출 주소 변경
혹시 다른 방식으로 호출해야할까 의심이 되어 클러스터 내부 DNS 주소, 클러스터 DNS, Backend Pod의 External-IP
로 바꾸어 한번씩 테스트 시도
http://journeyjinni-backend.journeyjinni.svc.cluster.local:80
(Axios 에러)- 57.155.17.41 (정상 호출)
http://journeyjinni-backend
(Axios 에러)
BackEnd Endpoint의 주소를 External-IP로 설정
백엔드 호출 주소를 External-IP
로 설정하니 정상 호출이 되었다.
아마 Axios 호출을 Pod에서 일어나는것이 아닌 브라우저에서 호출을 하기에 브라우저 → 백엔드 Pod으로 통신이 불가능하다고 생각되어 진다.
Ingress를 활용하여 요청을 Backend Pod으로 우회
nginx Ingress를 사용하여 /api
호출에 대해 내부 pod으로 요청을 프록시하는 방식을 구현하려고 한다.
하지만 AKS의 성능이 제일 저렴한 계획을 선택하였기에 Ingress-Controller가 정상적으로 배포되지를 못한다.. (현재 ArogCD도 약 10분 정도 있다가 작동됨)