Nginx Ingress로 로드 밸런싱 설정하기

궁금하면 500원·2024년 7월 26일
0

데브옵스

목록 보기
7/36

Nginx Ingress

Nginx Ingress Controller는 Kubernetes에서 HTTP 및 HTTPS 트래픽을 클러스터 내부의 서비스로 라우팅하는 역할을 합니다.

로드 밸런싱, SSL 종료, URL 경로 기반 라우팅 등을 지원합니다.

Nginx Ingress 설정

  • Ingress 리소스 정의: Kubernetes 클러스터에 Ingress 리소스를 정의하여 트래픽을 라우팅합니다.

예를 들어, 다음과 같은 YAML 파일로 Ingress를 설정할 수 있습니다.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              number: 80
  • 로드 밸런싱 설정: 기본적으로 Nginx는 round-robin 방식으로 로드 밸런싱을 수행합니다.

하지만 추가적인 로드 밸런싱 알고리즘을 설정하려면 주석을 추가할 수 있습니다.

annotations:
  nginx.ingress.kubernetes.io/load-balance: "least_conn"
  • 메모리 설정: Nginx Ingress의 메모리 사용량을 제어하려면 Ingress Controller의 Deployment에 리소스 요청과 제한을 설정할 수 있습니다.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-ingress-controller
spec:
  template:
    spec:
      containers:
      - name: nginx-ingress-controller
        resources:
          requests:
            memory: "128Mi"
            cpu: "100m"
          limits:
            memory: "256Mi"
            cpu: "500m"

Docker 메모리 설정

Docker에서는 컨테이너의 메모리 사용량을 제어할 수 있습니다.

Docker 컨테이너를 실행할 때 --memory 플래그를 사용하여 메모리 제한을 설정할 수 있습니다.

docker run --memory="256m" my-container
  • 메모리 요청: 컨테이너가 최소한으로 필요한 메모리 양.
  • 메모리 제한: 컨테이너가 사용할 수 있는 최대 메모리 양.

Docker Compose에서 설정하기

Docker Compose 파일에서도 메모리 설정을 할 수 있습니다.

version: '3.7'
services:
  my-service:
    image: my-image
    deploy:
      resources:
        limits:
          memory: 256M
        reservations:
          memory: 128M
profile
꾸준히, 의미있는 사이드 프로젝트 경험과 문제해결 과정을 기록하기 위한 공간입니다.

0개의 댓글