More Related Content
Similar to amazon eks network some of count help tip
Similar to amazon eks network some of count help tip (20)
More from HeeJung Chae (6)
amazon eks network some of count help tip
- 1. © 2023, Amazon Web Services, Inc. or its affiliates.
© 2023, Amazon Web Services, Inc. or its affiliates.
알아두면 쓸모있는 Amazon EKS
네트워킹 팁 몇 가지
Yongho Choi
Solutions Architect
AWS
- 2. © 2023, Amazon Web Services, Inc. or its affiliates.
© 2023, Amazon Web Services, Inc. or its affiliates.
Amazon EKS를 위한
네트워크 구성은?
- 3. © 2023, Amazon Web Services, Inc. or its affiliates.
잠깐! IP 기본 지식
• 사설 IP (Private IP)란 무엇이고 왜 쓸까요?
A 스타트업 (192.168.0.0/16)
- 4. © 2023, Amazon Web Services, Inc. or its affiliates.
(참고) 주소 범위 CIDR 이해하기
예) 사설 IP 대역 (RFC1918)
192.168.0.0/16
255.255.0.0
11111111.11111111.00000000.00000000
8 8
16
http://www.subnet-calculator.com/cidr.php
Subnet
Bits(CIDR)
# of hosts
/16 65,534
/17 32,766
/18 18,382
/19 8,190
/20 4,094
/21 2,046
/22 1,022
/23 510
/24 254
/25 128
/26 62
/27 30
/28 14
- 5. © 2023, Amazon Web Services, Inc. or its affiliates.
Subnet Subnet
Subnet Subnet
VPC
Availability Zone
ap-northeast-2A
Availability Zone
ap-northeast-2B
VPC 생성 : 서브넷 정의 및 IPv4 주소 대역 할당
172.31.0 172.31.1
172.31.128 172.31.129
- 6. © 2023, Amazon Web Services, Inc. or its affiliates.
가용영역 레벨의 고가용성 구성
• 최소 2개 이상의 가용 영역 사용 권장
AWS Cloud
Region
Availability Zone
Amazon VPC
인스턴스 1 인스턴스 2
Availability Zone
- 7. © 2023, Amazon Web Services, Inc. or its affiliates.
퍼블릭 서브넷
• 인터넷과 양방향 통신이 필요한가?
Amazon VPC
가용 영역 가용 영역
/16
프라이빗 서브넷
퍼블릭 서브넷
프라이빗 서브넷
퍼블릭 서브넷
/22
0.0.0.0/0 IGW
10.1.0.0/16 Local
Destination Target
- 8. © 2023, Amazon Web Services, Inc. or its affiliates.
프라이빗 서브넷
• 프라이빗 서브넷도 인터넷과 아웃바운드 통신은 필요하다면? – NAT
게이트웨이
Amazon VPC
가용 영역 가용 영역
/16
프라이빗 서브넷
퍼블릭 서브넷
프라이빗 서브넷
퍼블릭 서브넷
/22
0.0.0.0/0 IGW
10.1.0.0/16 Local
Destination Target
NAT 게이트웨이
EIP: 11.22.33.44
인스턴스 B
NAT GW
0.0.0.0/0
10.1.0.0/16 Local
Destination Target
- 9. © 2023, Amazon Web Services, Inc. or its affiliates.
NAT 게이트웨이
• NAT 게이트웨이 이중화 구성을 통한 가용 영역(AZ) 수준의 가용성 확보
Amazon VPC
가용 영역 가용 영역
/16
프라이빗 서브넷
퍼블릭 서브넷
프라이빗 서브넷
퍼블릭 서브넷
/22
0.0.0.0/0 IGW
10.1.0.0/16 Local
Destination Target
NAT 게이트웨이
EIP: 11.22.33.44
인스턴스 B
NAT GW
0.0.0.0/0
10.1.0.0/16 Local
Destination Target
EIP: 11.33.44.55
- 10. © 2023, Amazon Web Services, Inc. or its affiliates. 10
그럼 Amazon EKS에서는 어떻게 서브넷을 구성해야 할까요?
- 11. © 2023, Amazon Web Services, Inc. or its affiliates.
10.0.11.0/20 10.0.12.0/20 10.0.13.0/20
AZ 1A
Amazon EKS Networking
Customer VPC 10.0.0.0/16
Amazon Managed VPC
API Server
EKS Control Plane
Data Plane
10.0.1.0/28
AZ 1B AZ 1C
10.0.2.0/28
워커 노드들은 프라이빗 서브넷에 생성
- 12. © 2023, Amazon Web Services, Inc. or its affiliates. 12
그럼 외부에서 들어오는 트래픽을
어떻게 노드 또는 Pod로 전달할까요?
- 13. © 2023, Amazon Web Services, Inc. or its affiliates. 13
Pod A
Pod B
Application Load Balancer
Service A -Target Group
(인스턴스모드)
Service B -Target Group
(인스턴스모드)
Service C-Target Group
(IP 모드)
Network Load Balancer
Pod A
Pod B Pod C
Pod A
Pod D
ALB Ingress
Controller
Pod C
Pod D
NP-
B NP-
A NP-
B NP-
A
Pod C
NP-
A
https://github.com/kubernetes-sigs/aws-load-balancer-controller
상태 업데이트
Watch
규칙: /dog 규칙: /cat 규칙: /pets
API Server
로드밸런서를 사용하여 외부 트래픽 Pod로 분배
- 14. © 2023, Amazon Web Services, Inc. or its affiliates.
서브넷 자동 탐색
Private Subnet
Public Subnet
Tags:
kubernetes.io/role/elb: 1
kubernetes.io/cluster/${cluster-name}: shared*
Tags:
kubernetes.io/role/internal-elb: 1
kubernetes.io/cluster/${cluster-name}: shared*
로드 밸런서는 서브넷에 할당된 태그를 기반으로 서브넷에 배치됩니다.
* Not needed in versions 1.19 or later
- 15. © 2023, Amazon Web Services, Inc. or its affiliates.
EKS에서 Network Load Balancer 프로비저닝
kind: Service
apiVersion: v1
metadata:
name: nginx-service
namespace: ingress-nginx
annotations:
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: 'true’
service.beta.kubernetes.io/aws-load-balancer-type: nlb
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
spec:
type: LoadBalancer
externalTrafficPolicy: Cluster
selector:
app: nginx
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 80
in-tree service controller 사용
- 16. © 2023, Amazon Web Services, Inc. or its affiliates.
EKS에서 Network Load Balancer 프로비저닝
Customer VPC
Data Plane
Pod Pod
NodePort
kubectl apply –f
Cloud Controller Manager
EKS VPC
Control Plane
Service Controller
CLB/NLB
provisioning
Listener
Target Group
- 17. © 2023, Amazon Web Services, Inc. or its affiliates.
EKS에서 Network Load Balancer 프로비저닝
kubectl apply –f
NodePort: 31245
ClusterIP: 172.20.84.55
Port: 80
Service
Pod
10.0.1.101:8080
Pod
10.0.1.102:8080
Node1
31245
Node2
31245
EKS VPC
Control Plane
Cloud Controller Manager
Service Controller
CLB/NLB
provisioning
- 18. © 2023, Amazon Web Services, Inc. or its affiliates.
Network Load Balancer 프로비저닝 시 Target 유형 지정
kind: Service
apiVersion: v1
metadata:
name: nginx-service
namespace: ingress-nginx
annotations:
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: “true”
service.beta.kubernetes.io/aws-load-balancer-type: "external"
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: “instance"
service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 80
AWS Load Balancer controller 사용
version 2.2.0 이상 필요
- 19. © 2023, Amazon Web Services, Inc. or its affiliates.
AWS Load Balancer Controller에 의한 Target 유형 설정
kubectl apply –f
EKS VPC
Control Plane
Cloud Controller Manager
Service Controller
Customer VPC
Data Plane
Listener
Target Group
Pod Pod
NodePort
AWS Load
Balancer
Controller
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance
NLB provisioning
- 20. © 2023, Amazon Web Services, Inc. or its affiliates.
AWS Load Balancer Controller에 의한 Target 유형 설정
kubectl apply –f
EKS VPC
Control Plane
Cloud Controller Manager
Service Controller
Customer VPC
Data Plane
Listener
Target Group
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
AWS Load
Balancer
Controller
NLB provisioning
Pod Pod
- 21. © 2023, Amazon Web Services, Inc. or its affiliates.
AWS Load
Balancer
Controller
AWS Load Balancer Controller에 의한 Target 유형 설정
kubectl apply –f
EKS VPC
Control Plane
Cloud Controller Manager
Service Controller
Customer VPC
Data Plane
Pod1
10.0.1.101:8080
Pod2
10.0.1.102:8080
NLB provisioning
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
- 22. © 2023, Amazon Web Services, Inc. or its affiliates.
EKS에서 Application Load Balancer 프로비저닝
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: echoserver-ingress
namespace: echoserver
annotations:
alb.ingress.kubernetes.io/security-groups: sg-010fc3455c73f0a58, sg-049e999c68a291976
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/group.name: web-services
kubernetes.io/ingress.class: alb
spec:
ingressClassName: alb-ingress-class
rules:
- host: echoserver.example.com
http:
paths:
- path: /*
backend:
serviceName: echoserver-svc
servicePort: 80
kubernetes-sigs/aws-load-balancer-controller
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: alb-ingress-class
spec:
controller: ingress.k8s.aws/alb
- 23. © 2023, Amazon Web Services, Inc. or its affiliates.
AWS Load
Balancer
Controller
Ingress Rule을 사용하여 대상 서비스로 라우팅
kubectl apply –f
EKS VPC
Control Plane
Customer VPC
Data Plane
Listener
Target Group
Echo Pod Echo Pod
ALB provisioning
Ingress Rules
- 24. © 2023, Amazon Web Services, Inc. or its affiliates.
AWS Load
Balancer
Controller
IngressGroup으로 여러 Ingress 리소스를 단일 ALB로 결합
kubectl apply –f
Application
Load balancer
provisioning
EKS VPC
Control Plane
Customer VPC
Data Plane
Listener
Target Group 2
App1 Pod App1 Pod
App2 Pod App2 Pod
Target Group 1
alb.ingress.kubernetes.io/group.name: web-services
Ingress Rules
(App1)
Ingress Rules
(App2)
- 25. © 2023, Amazon Web Services, Inc. or its affiliates.
© 2023, Amazon Web Services, Inc. or its affiliates.
DNS 성능 문제를 해결하려면?
- 26. © 2023, Amazon Web Services, Inc. or its affiliates.
How DNS Works in Kubernetes
VPC
10.0.0.0/16
Route 53
Resolver
10.0.0.2
Upstream DNS
Name Server
• CoreDNS add-on은 EKS 클러스터 내에서
리소스들의 DNS명을 확인(resolve)함
• VPC 용 기본 Route 53 Resolver는 VPC
내에서 클러스터 외부에 있는 리소스를
확인함
• VPC 내부에서 찾을 수 없다면 외부
리소스를 확인하기 위해 업스트림 DNS
name server로 요청
- 27. © 2023, Amazon Web Services, Inc. or its affiliates.
How CoreDNS Works
nameserver 10.100.0.10
search default.svc.cluster.local svc.cluster.local cluster.local us-west-2.compute.internal
options ndots:5
각 컨테이너들은 Kubelet에 의해 /etc/resolv.conf 를 상속 받음
Lookup DNS Name
Is this a FQDN?
CoreDNS
ClusterIP: 10.100.0.10
Yes
No
Query with FQDN
Query with each search domain as suffix
Upstream
Resolver
getaddrinfo
syscall
- 28. © 2023, Amazon Web Services, Inc. or its affiliates.
How CoreDNS Works
nameserver 10.100.0.10
search default.svc.cluster.local svc.cluster.local cluster.local us-west-2.compute.internal
options ndots:5
Lookup aws.com.
Is this a FQDN?
CoreDNS
ClusterIP: 10.100.0.10
Yes
Query with aws.com.
점(.)으로 끝났기 때문에 FQDN으로 처리됨
각 컨테이너들은 Kubelet에 의해 /etc/resolv.conf 를 상속 받음
- 29. © 2023, Amazon Web Services, Inc. or its affiliates.
How CoreDNS Works
nameserver 10.100.0.10
search default.svc.cluster.local svc.cluster.local cluster.local us-west-2.compute.internal
options ndots:5
Lookup ABC123.gr7.us-west-2.eks.amazonaws.com
Is this a FQDN?
CoreDNS
ClusterIP: 10.100.0.10
Yes
Query with ABC123.gr7.us-west-2.eks.amazonaws.com
5개의 점(.)을 포함
각 컨테이너들은 Kubelet에 의해 /etc/resolv.conf 를 상속 받음
- 30. © 2023, Amazon Web Services, Inc. or its affiliates.
app.nodejs.svc.default.svc.cluster.local.
app.nodejs.svc.svc.cluster.local.
app.nodejs.svc.cluster.local.
app.nodejs.svc.us-west-2.compute.internal.
app.nodejs.svc.
How CoreDNS Works
nameserver 10.100.0.10
search default.svc.cluster.local svc.cluster.local cluster.local us-west-2.compute.internal
options ndots:5
No
Lookup app.nodejs.svc
Is this a FQDN?
CoreDNS
ClusterIP: 10.100.0.10
Query
with
5개보다 점(.)이 부족
각 컨테이너들은 Kubelet에 의해 /etc/resolv.conf 를 상속 받음
- 31. © 2023, Amazon Web Services, Inc. or its affiliates.
Tuning CoreDNS
spec:
containers:
- name: node
image: nodeapp:v1.0.0
resources:
requests:
cpu: "128m"
memory: "128Mi”
dnsConfig:
options:
- name: ndots
value: 2
• ndots는 주소가 FQDN인지 확인하는 데 사용
• Kubernetes 기본값은 5
• Pod 사양에서 dnsConfig로 재정의됨
• 워크로드별로 개별 지정
• ndots = 2로 설정
• aws.amazon.com과 같이 dot이 2개 이상인
경우 suffix를 붙이지 않고 FQDN으로 인식
• CoreDNS로 쿼리가 줄기 때문에 부하 감소
- 32. © 2023, Amazon Web Services, Inc. or its affiliates.
Scaling CoreDNS
• 기본적으로 CoreDNS는 EKS 클러스터에 2개의 복제본으로 배포됨
• CoreDNS 배포를 자동 확장하는 두 가지 방법
• CPA(Cluster Proportional Autoscaling) : 클러스터 규모에 따라 확장
• HPA(Horizontal Pod Autoscaling) : Pod 리소스 임계치 기반의 확장
- 33. © 2023, Amazon Web Services, Inc. or its affiliates.
CoreDNS 모니터링
linklocal_allowance_exceeded : PPS가 네트워크 인터페이스의 최대값을 초과하여 삭제된 패킷의 수
• Link local은 인터넷으로 나가지 않는 내부 패킷을 의미
- 34. © 2023, Amazon Web Services, Inc. or its affiliates.
Node Local DNS Cache 사용
- 35. © 2023, Amazon Web Services, Inc. or its affiliates.
Thank you!
© 2023, Amazon Web Services, Inc. or its affiliates.