- ngress 란
- 클러스터 외부에서 내부로 접근하는 요청들을 어떻게 처리할 지 정의해둔 규칙들의 모음
- Ingress의 기능
- 외부에서 접속 가능한 URL 사용
- 트래픽 로드밸런싱
- SSL 인증서 처리
- 도메인 기반 가상 호스팅 제공
- Ingress Controller 란
- 클러스터에서 실행되고 수긴 리소스에 따라 HTTP 로드 밸런서를 구성하는 응용 프로그램
- Ingress가 동작하기 위해서는 Ingress Controller 필요
- Ingress Controller 통신 흐름
- AWS Load Balancer Controller 설치
- Nginx Ingress Controller 설치
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install ingress-nginx ingress-nginx/ingress-nginx -n kube-system
- AWS NLB 생성
- Nginx Ingress Controller에서 타겟 타입 ip를 지원하지 않기 때문에 AWS Load Balancer Controller 같이 사용해야 타겟 타입을 IP로 생성할 수 있음
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
service.beta.kubernetes.io/aws-load-balancer-subnets: subnet-0e3b82a26c19c99f9, subnet-01f2f26c1054492a1
service.beta.kubernetes.io/aws-load-balancer-type: nlb
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: arn:aws:acm:ap-northeast-2:759320821027:certificate/285c43fd-6bbc-441a-aba7-46d37eb18a58
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: tcp
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443"
service.beta.kubernetes.io/aws-load-balancer-healthcheck-port: "80" # 헬스 체크 포트를 80으로 설정
service.beta.kubernetes.io/aws-load-balancer-name: ydy-nginx-ingress-test
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.7.0
name: ingress-nginx-controller
namespace: nginx-ingress
spec:
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- appProtocol: http
name: http
port: 80
protocol: TCP
targetPort: 80 # 타겟 포트를 80으로 설정
- appProtocol: https
name: https
port: 443
protocol: TCP
targetPort: 80
selector:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
type: LoadBalancer
- Ingress 배포
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: yeom-ingress
namespace: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /yeom1
pathType: Prefix
backend:
service:
name: yeom-svc1 # 트래픽을 라우팅할 서비스
port:
number: 80
- path: /yeom2
pathType: Prefix
backend:
service:
name: yeom-svc2
port:
number: 80
- path: /yeom3
pathType: Prefix
backend:
service:
name: yeom-svc3
port:
number: 80
kubectl apply -f ingress.yaml
- Deploymenet / Service 배포
apiVersion: apps/v1
kind: Deployment
metadata:
name: yeom-deploy1
namespace: nginx-ingress
spec:
replicas: 3
selector:
matchLabels:
app: yeomdeploy1
template:
metadata:
labels:
app: yeomdeploy1
spec:
containers:
- name: yeomtainer1
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: nginx-ingress
name: yeom-svc1
spec:
ports:
- name: yeom-svc-port
port: 80
targetPort: 80
selector:
app: yeomdeploy1
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
apiVersion: apps/v1
kind: Deployment
metadata:
name: yeom-deploy2
namespace: nginx-ingress
spec:
replicas: 3
selector:
matchLabels:
app: yeomdeploy2
template:
metadata:
labels:
app: yeomdeploy2
spec:
containers:
- name: yeomtainer2
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: nginx-ingress
name: yeom-svc2
spec:
ports:
- name: yeom-svc-port
port: 80
targetPort: 80
selector:
app: yeomdeploy2
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
apiVersion: apps/v1
kind: Deployment
metadata:
name: yeom-deploy3
namespace: nginx-ingress
spec:
replicas: 3
selector:
matchLabels:
app: yeomdeploy3
template:
metadata:
labels:
app: yeomdeploy3
spec:
containers:
- name: yeomtainer3
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: nginx-ingress
name: yeom-svc3
spec:
ports:
- name: yeom-svc-port
port: 80
targetPort: 80
selector:
app: yeomdeploy3
kubectl apply -f deploymenet1.yaml
kubectl apply -f deploymenet2.yaml
kubectl apply -f deploymenet3.yaml
- 결과 확인
- Route53을 통해 도메인 연결
- curl 명령어로 확인
'AWS' 카테고리의 다른 글
[AWS] EKS - Cluster Autoscaler 설정 (0) | 2024.09.29 |
---|---|
[AWS] EKS - Horizontal Pod AutoScaler ( HPA ) 설정 (8) | 2024.09.29 |
[AWS] EKS - Load Balancer Controller 설치 및 ALB 생성 (0) | 2024.09.29 |
[AWS] EKS Cluster 생성 (0) | 2024.09.21 |
[AWS] S3, Athena, Lambda - 최근 액세스 날짜 기준 이후의 객체 삭제 (0) | 2024.09.21 |