kubernetes:nginx-ingress实现二级目录
需求1说明
要求:
https://devhtk.ntmaorong.com/minio/ ---> 访问 http://10.10.246.29:9000/minio/
service+endpoint+ingress配置
apiVersion: v1
kind: Service
metadata:
labels:
app: vchain-minio
name: vchain-minio
namespace: haian-dev
spec:
ports:
- name: tcp-9000
port: 9000
protocol: TCP
targetPort: 9000
selector:
app: vchain-minio
sessionAffinity: None
type: ClusterIP
---
apiVersion: v1
kind: Endpoints
metadata:
labels:
app: vchain-minio
name: vchain-minio
namespace: haian-dev
subsets:
- addresses:
- ip: 10.10.246.29
ports:
- name: tcp-9000
port: 9000
protocol: TCP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginn.ingress.kubernetes.io/proxy-body-size: 50m
nginx.ingress.kubernetes.io/rewrite-target: /minio/(.*)
nginx.ingress.kubernetes.io/use-regex: "true"
name: vchain-minio
namespace: haian-dev
spec:
ingressClassName: nginx
rules:
- host: devhtk.ntmaorong.com
http:
paths:
- backend:
service:
name: vchain-minio
port:
number: 9000
path: /minio/(.*)
pathType: ImplementationSpecific
tls:
- hosts:
- devhtk.ntmaorong.com
secretName: ntmaorong-secret
启动:
# kubectl create -f vchain-minio.yaml
检查效果
内网地址访问效果:
外网地址访问效果:
外网地址原来的页面没有受到影响:
需求2说明
要求:https://idata.gmoregalax.com/sincerewatch/ ---> http://172.16.0.239:8001/
配置
Service+Endpoints配置
apiVersion: v1
kind: Service
metadata:
labels:
app: sincerewatch
name: sincerewatch
namespace: dmp-prod
spec:
ports:
- name: tcp-8001
port: 8001
protocol: TCP
targetPort: 8001
type: ClusterIP
---
apiVersion: v1
kind: Endpoints
metadata:
labels:
app: sincerewatch
name: sincerewatch
namespace: dmp-prod
subsets:
- addresses:
- ip: 172.16.0.239
ports:
- name: tcp-8001
port: 8001
protocol: TCP
ingress配置
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false" # 确保不强制重定向到 HTTPS
nginx.ingress.kubernetes.io/proxy-body-size: 100m
nginx.ingress.kubernetes.io/rewrite-target: /$2 # 重写路径,这个代表的是被代理的172.16.0.239路径
nginx.ingress.kubernetes.io/use-regex: "true" #是否使用正则表达式,true表示使用
nginx.ingress.kubernetes.io/enable-cors: "true" # 启用跨域资源共享(CORS)
name: sincerewatch
namespace: dmp-prod
spec:
ingressClassName: nginx
rules:
- host: idata.gmoregalax.com
http:
paths:
- backend:
service:
name: sincerewatch
port:
number: 8001
path: /sincerewatch(/|$)(.*) #这里表示域名上需要重新的二级目录
pathType: Prefix
tls:
- hosts:
- idata.gmoregalax.com
secretName: dmpssl-secret
启动
kubectl create -f 文件名称