반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- operator
- Kubernetes 인증
- xdp
- Argo
- kubernetes operator
- opentelemetry
- MLflow
- argocd
- 오퍼레이터
- Model Serving
- 카오스 엔지니어링
- Continuous Deployment
- mlops
- nginx ingress
- blue/green
- Kubeflow
- tekton
- CI/CD
- knative
- Litmus
- Pulumi
- Kopf
- gitops
- seldon core
- Kubernetes
- CANARY
- serving
- eBPF
- keda
- opensearch
Archives
- Today
- Total
Kubernetes 이야기
Nginx Ingress Path 기반 라우팅 설정 본문
반응형
Nginx Ingress에서 Path 기반 라우팅 설정하는 방법을 간단히 알아보자.
예제1) 정규식 표현
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
ingressClassName: nginx
rules:
- host: test.com
http:
paths:
- path: /foo/.*
pathType: Prefix
backend:
service:
name: test
port:
number: 80
예제2) Path 우선순위
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-example
spec:
ingressClassName: nginx
rules:
- host: test.com
http:
paths:
- path: /foo/bar
pathType: Prefix
backend:
service:
name: service1
port:
number: 80
- path: /foo/bar/
pathType: Prefix
backend:
service:
name: service2
port:
number: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-example
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
ingressClassName: nginx
rules:
- host: test.com
http:
paths:
- path: /foo/bar/(.+)
pathType: Prefix
backend:
service:
name: service3
port:
number: 80
- test.com/foo/bar/1 matches ~* ^/foo/bar/.+ and will go to service 3.
- test.com/foo/bar/ matches ~* ^/foo/bar/ and will go to service 2.
- test.com/foo/bar matches ~* ^/foo/bar and will go to service 1.
예제3) rewrite
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: ingress-example
spec:
rules:
- host: test.com
http:
paths:
- path: /service(/|$)(.*)
pathType: Prefix
backend:
service:
name: test
port:
number: 80
- /service -> /
- /service/a1 -> /a1
예제4) App Root
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/app-root: /test1
name: ingress-example
spec:
rules:
- host: test.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service1
port:
number: 80
test.com로 접속을 하면 test.com/test1 경로로 redirect 된다.
예제5) 확장자 정규식
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
kubernetes.io/ingress.class: nginx
name: ingress-example
spec:
rules:
- host: test.com
http:
paths:
- path: '/*'
pathType: Prefix
backend:
service:
name: backend
port:
number: 8080
- path: '/.*\.(jpg|svg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm|ttf|woff|woff2)$'
pathType: Prefix
backend:
service:
name: frontend
port:
number: 80
apache service와 tomcat service가 구분되어 있을 경우 확장자 형태로 분기할 수 있다.
반응형
'Kubernetes > 일반' 카테고리의 다른 글
Pod에서 imagePullSecrets 설정하기 (0) | 2022.03.24 |
---|---|
kubernetes yaml 을 helm chart로 변환하기 (0) | 2022.03.15 |
로컬 Kubernetes 클러스터 - kind 설치 (0) | 2022.03.08 |
Nginx Ingress 트래픽 모니터링 결과로 Auto Scale 사용하기 (0) | 2022.02.28 |
kubernetes coredns 에 hosts 등록하기 (0) | 2022.02.22 |
Comments