쿠버네티스에서 Nginx Ingress 사용하기

Adam·2022년 5월 17일
0

KubernetesBasic

목록 보기
6/6

쿠버네티스 Nginx

외부에서 특정 쿠버네티스 pod에 접근을 하기 위해서 ingress가 필요하다.
쿠버내티스에서 다양한 ingress들을 제공하지만 가장 대표적인 것이 nginx ingress이다.

Nginx ingress controller가 작동하는 방식은 아래의 그림과 같이 Nginx ingress controller pod이 외부의 트래픽을 받아 들이고, 해당 ingress에 연결된 다른 ingress 혹은 service에 해당 트래픽을 전달해 주는 역할을 한다.

설치

쿠버네티스 클러스터에 nginx를 설치하는 방법은 github에 있는 코드를 통한 방법과, helm을 사용하는 방법이 있는데 helm을 사용해 설치하는 방법에 대해서 말해보려한다.

우선 helm repo에 Nginx ingress를 추가해준다.

helm repo add ingress-nginx \
  https://kubernetes.github.io/ingress-nginx

values.yaml을 생성해 디폴트 값을 변경해 줄 수 있으나, 디폴트 값으로 helm chart를 생성하도록 하겠다.

helm template my-ing ingress-nginx/ingress-nginx \
  --namespace ingress \
  --version 3.35.0 \
  --values values.yaml \
  --output-dir my-ing

Helm을 통해 Nginx ingress 설치

helm install my-ing ingress-nginx/ingress-nginx \
  --namespace ingress \
  --version 3.35.0 \
  --values values.yaml \
  --create-namespace

설치가 잘 된지 확인을 해준다.

kubectl get pods -n ingress

서비스를 통해 해당 pod의 주소를 알 수 있다.

kubectl get svc -n ingress

Nginx controller에 연결

서비스 하고 싶은 팟에 해당하는 ingress에 해당 Nginx ingress controller을 연결시켜줘야 한다.
연결시키려는 ingress의 spec에 ingressClassName에 설치한 nginx의 이름 이 경우엔 "external-nginx"애 연결 시켜준다.

spec:
  ingressClassName: external-nginx
profile
Keep going하는 개발자

0개의 댓글