내부 통신에서도 ingress-nginx-controller 를 많이 사용하는데, 그 기능 중에 base path 를 기준으로 호출하는 서비스를 구분하는 기능에 대해서 알아본다.

 

아래와 같이 Ingress 의 annotations 에 설정한다

  • nginx.ingress.kubernetes.io/use-regx: "true"
  • nginx.ingress.kubernetes.io/rewrite-target: /$2

그리고 spec.rules[].paths.path: /<basePath>(/|$)(.*) 를 설정하면 basePath 를 기준으로 특정 서비스로 트래픽을 연결할 수 있다. 서비스로 연결될 때에는 basePath 부분은 제거되고 /$2 부분만 사용된다.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: sample-ns
  name: core-internal
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
          - path: /core(/|$)(.*)
            pathType: ImplementationSpecific
            backend:
              service:
                name: core-api
                port:
                  number: 80

 

 

참고: 

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite

 

Annotations - Ingress-Nginx Controller

Annotations You can add these Kubernetes annotations to specific Ingress objects to customize their behavior. Tip Annotation keys and values can only be strings. Other types, such as boolean or numeric values must be quoted, i.e. "true", "false", "100". Ca

kubernetes.github.io

 

블로그 이미지

망원동똑똑이

프로그래밍 지식을 자유롭게 모아두는 곳입니다.

,