Kubernetes, Ingress Controller

Jeonghak Cho·2025년 2월 16일

Kubernetes

목록 보기
3/20

Ingress, Ingress Controller 개요

Kubernetes에서 외부 트래픽을 클러스터 내부 서비스로 전달하려면 Ingress와 Ingress Controller가 필요하다.

  • Ingress는 트래픽 라우팅 규칙을 정의하는 Kubernetes 리소스
  • Ingress Controller는 Ingress 설정을 적용하고 실제 트래픽을 서비스로 전달
  • 단순히 Ingress를 생성해도 동작하지 않으며, 반드시 Ingress Controller가 필요
  • Ingress Controller는 다양한 구현체(NGINX, Traefik, Istio Gateway 등)가 존재하며, 필요에 따라 선택 가능

Ingress는 단순히 설정(규칙)을 정의하는 리소스이고, 실제 트래픽을 처리하려면 반드시 Ingress Controller가 필요하다.

Ingress 개요

  • Kubernetes에서 외부 HTTP/HTTPS 트래픽을 내부 서비스로 라우팅하는 API 리소스
  • 기본적으로 L7 (Application Layer) 트래픽을 제어
  • 도메인 기반(Route) 트래픽 라우팅이 가능 (example.com → 서비스 A)
  • TLS(HTTPS) 설정 및 리다이렉트 같은 기능 지원
  • 단독으로는 작동하지 않으며, 반드시 Ingress Controller가 필요

example.com으로 들어오는 요청을 my-service로 전달하는 Ingress 예시

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
    - host: example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 80

Ingress Controller 개요

  • Ingress 리소스의 설정을 해석하고, 실제로 트래픽을 서비스로 전달하는 역할
  • Ingress는 정책(규칙)만 정의, 실제 트래픽 처리는 Ingress Controller가 담당
  • 여러 종류의 Ingress Controller가 존재하며, 대표적으로 NGINX Ingress Controller, Traefik, HAProxy, Istio Gateway 등이 있음

대표적인 Ingress Controller 예시

NGINX Ingress Controller

  • 가장 널리 사용됨
  • Kubernetes 내부에서 NGINX를 실행하여 Ingress 트래픽을 처리

Traefik

  • 자동 서비스 디스커버리 기능 제공
  • Kubernetes뿐만 아니라 다양한 플랫폼과 연동 가능

Istio Gateway (Ingress 기능 포함)

  • Istio 서비스 메시에 최적화된 Ingress 솔루션
  • mTLS, L4~L7 트래픽 제어 가능

Ingress vs. Ingress Controller 비교

항목IngressIngress Controller
역할트래픽 라우팅 규칙 정의실제 트래픽을 처리하는 컨트롤러
동작 방식Ingress 리소스를 생성하면 끝Ingress를 감시하고 라우팅 수행
단독 실행 가능 여부❌ 불가능 (컨트롤러 필요)✅ 가능
L7 트래픽 처리✅ 가능 (HTTP/HTTPS 라우팅)✅ 가능 (컨트롤러에 따라 지원 기능 다름)
로드 밸런싱❌ 직접 수행하지 않음✅ 가능 (Ingress Controller 내부에서 처리)
대표적인 구현체Kubernetes 기본 리소스NGINX, Traefik, Istio Gateway 등

Nginx ingress controller 설치

vagrant@master:~$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
"ingress-nginx" has been added to your repositories

vagrant@master:~$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "ingress-nginx" chart repository
...Successfully got an update from the "istio" chart repository
Update Complete. ⎈Happy Helming!
vagrant@master:~$ helm install nginx-ingress ingress-nginx/ingress-nginx -n nginx-controller --create-namespace
NAME: nginx-ingress
LAST DEPLOYED: Sun Feb 16 12:12:00 2025
NAMESPACE: nginx-controller
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The ingress-nginx controller has been installed.
It may take a few minutes for the load balancer IP to be available.
You can watch the status by running 'kubectl get service --namespace nginx-controller nginx-ingress-ingress-nginx-controller --output wide --watch'

An example Ingress that makes use of the controller:
  apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: example
    namespace: foo
  spec:
    ingressClassName: nginx
    rules:
      - host: www.example.com
        http:
          paths:
            - pathType: Prefix
              backend:
                service:
                  name: exampleService
                  port:
                    number: 80
              path: /
    # This section is only required if TLS is to be enabled for the Ingress
    tls:
      - hosts:
        - www.example.com
        secretName: example-tls

If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:

  apiVersion: v1
  kind: Secret
  metadata:
    name: example-tls
    namespace: foo
  data:
    tls.crt: <base64 encoded cert>
    tls.key: <base64 encoded key>
  type: kubernetes.io/tls
  • 확인
vagrant@master:~$ k get po -n nginx-controller
NAME                                                      READY   STATUS    RESTARTS   AGE
nginx-ingress-ingress-nginx-controller-6f6bf998dc-tn9bt   1/1     Running   0          89s

테스트 용 nginx POD 생성

kubectl run nginx --image=nginx

vagrant@master:~$ kubectl run nginx --image=nginx
pod/nginx created

vagrant@master:~$ k get po
NAME                             READY   STATUS     RESTARTS   AGE
nginx                            2/2     Running   0          34s

테스트 용 nginx SERVICE 생성

k run mynginx --image nginx --expose --port 80

vagrant@master:~$ k run mynginx --image nginx --expose --port 80
service/mynginx created
pod/mynginx created

vagrant@master:~$ k get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP    10h
mynginx      ClusterIP   10.105.27.85    <none>        80/TCP     3s

//helm upgrade --install nginx-ingress ingress-nginx/ingress-nginx -n nginx

INGRESS 생성

  • vi ing-mynginx.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mynginx
spec:
  ingressClassName: nginx
  rules:
  - host: localhost
    http:
      paths:
        - pathType: Prefix
          backend:
            service:
              name: mynginx
              port:
                number: 80
          path: /
vagrant@master:~$ k apply -f ing-mynginx.yml
ingress.networking.k8s.io/mynginx created

vagrant@master:~$ k get ing
NAME      CLASS   HOSTS       ADDRESS   PORTS   AGE
mynginx   nginx   localhost             80      4s

vagrant@master:~$ k get po
NAME                             READY   STATUS    RESTARTS   AGE
mynginx                          2/2     Running   0          8m38s

INGRESS 테스트

vagrant@master:~$ k exec -it mynginx -- curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

0개의 댓글