Less than 1 minute
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hellok8s-ingress
annotations: # 通过注解来进一步控制nginx控制器的行为,参考 https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/
nginx.ingress.kubernetes.io/rewrite-target: / # 匹配路由后,重写为 /; 比如 /hello 重写为 /
spec:
ingressClassName: nginx # 指定ingress控制器
rules:
- http:
paths:
- path: /hello # 默认不区分大小写,匹配/hello/123 不匹配/hello123
# 路径匹配类型
# - Prefix:前缀匹配,路由直接透传不会截断;另外还有 Exact、ImplementationSpecific类型
# - Exact:精确匹配 URL 路径,且区分大小写
# - ImplementationSpecific:默认匹配方式,具体由 ingressClass 决定
pathType: Prefix
backend:
service:
name: service-hellok8s-clusterip
port:
number: 3000
- path: /httpd
pathType: Prefix
backend:
service:
name: service-httpd
port:
number: 8080