내부 통신에서도 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
'Kubernetes' 카테고리의 다른 글
| [KUBERNETES] nginx ingress log 포멧 변경하기 (0) | 2026.08.01 |
|---|---|
| [KUBERNETES] ingress-nginx-controller 의 로드밸런싱 정책을 ewma 로 변경하기 (0) | 2026.08.01 |
| [KUBERNETES] Ingress 에서 http 요청을 https + 특정 포트로 리다이렉트 하기 (0) | 2026.07.29 |
| [KUBERNETES] Ingress 에서 SSL Redirect 하기 (0) | 2026.07.29 |
| [KUBERNETES] tls 인증서를 Ingress 에 적용하기 (0) | 2026.07.29 |