Ingress 기본 소개 및 간단한 Ingress YAML 예시
이 단계에서는 Kubernetes 클러스터에서 서비스에 대한 외부 액세스를 관리하는 강력한 방법인 Kubernetes Ingress 에 대해 배우게 됩니다.
Ingress 란 무엇인가?
Ingress 는 일반적으로 HTTP 인 Kubernetes 클러스터 내 서비스에 대한 외부 액세스를 관리하는 API 객체입니다. Ingress 는 다음을 제공합니다:
- 로드 밸런싱 (Load balancing): 여러 백엔드 서비스로 트래픽을 분산합니다.
- SSL/TLS 종료 (termination): 보안 연결을 처리합니다.
- 이름 기반 가상 호스팅 (Name-based virtual hosting): 호스트 이름을 기반으로 요청을 다른 서비스로 라우팅합니다.
- 경로 기반 라우팅 (Path-based routing): URL 경로를 기반으로 요청을 다른 서비스로 라우팅합니다.
Ingress 는 두 가지 구성 요소로 구성됩니다:
- Ingress 리소스 (Resource): 라우팅 규칙을 정의하는 Kubernetes API 객체
- Ingress 컨트롤러 (Controller): Ingress 리소스에 정의된 규칙을 적용하는 구현
참고: 이 랩에서는 Ingress 에 대한 기본적인 소개만 제공합니다. 프로덕션 환경에서는 Ingress 구성이 고급 라우팅, 인증, 속도 제한 등을 포함하여 훨씬 더 복잡할 수 있습니다.
Minikube 에서 Ingress 애드온을 활성화해 보겠습니다:
minikube addons enable ingress
예시 출력:
💡 ingress is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.
🔉 ingress was successfully enabled
두 개의 샘플 애플리케이션에 대한 배포를 생성합니다:
kubectl create deployment web1 --image=nginx:alpine
kubectl create deployment web2 --image=httpd:alpine
이러한 배포를 서비스로 노출합니다:
kubectl expose deployment web1 --port=80 --type=ClusterIP --name=web1-service
kubectl expose deployment web2 --port=80 --type=ClusterIP --name=web2-service
Ingress YAML 파일을 생성합니다:
nano ingress-example.yaml
다음 Ingress 구성을 추가합니다:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /web1
pathType: Prefix
backend:
service:
name: web1-service
port:
number: 80
- path: /web2
pathType: Prefix
backend:
service:
name: web2-service
port:
number: 80
이 Ingress 구성의 주요 구성 요소:
- metadata.annotations: Ingress 컨트롤러에 대한 특정 구성
- spec.rules: 트래픽을 서비스로 라우팅하는 방법 정의
- path: 일치할 URL 경로
- pathType: 경로를 일치시키는 방법 (Prefix, Exact, 또는 ImplementationSpecific)
- backend.service: 트래픽을 라우팅할 서비스 및 포트
Ingress 구성을 적용합니다:
kubectl apply -f ingress-example.yaml
Ingress 리소스를 확인합니다:
kubectl get ingress
예시 출력:
NAME CLASS HOSTS ADDRESS PORTS AGE
example-ingress nginx * 192.168.49.2 80 1m
Ingress 세부 정보를 확인합니다:
kubectl describe ingress example-ingress
예시 출력은 라우팅 규칙과 백엔드 서비스를 보여줍니다.
Ingress 테스트:
## Get the Minikube IP
minikube ip
## Test access to the services through Ingress
curl $(minikube ip)/web1
curl $(minikube ip)/web2
각 명령은 해당 웹 서버에서 기본 페이지를 반환해야 합니다.
프로덕션 환경에서 Ingress 는 다음과 같이 구성할 수 있습니다:
- 여러 호스트 이름 기반 규칙
- HTTPS 용 TLS 인증서
- 인증 메커니즘
- 속도 제한
- 사용자 지정 시간 초과 구성
- 세션 선호도
- 그리고 더 많은 고급 기능
Ingress 에 대한 보다 포괄적인 내용을 보려면 Kubernetes 문서를 참조하고 NGINX Ingress 또는 Traefik 과 같은 전용 Ingress 컨트롤러 문서를 살펴보십시오.