我有一个应用程序后端和前端,我想使用前缀分隔流量/api
我通常使用 Nginx 和 docker-compose 使用此配置执行此操作:
upstream server {
server backend:6969;
}
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location /api {
proxy_pass http://server;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
try_files $uri $uri/ /index.html;
}
}
现在我想使用 Kubernetes 入口做同样的工作,我在我的集群中使用 Kubeadm 和https://haproxy-ingress.github.io/作为入口控制器
这是我的入口 yaml:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: haproxy
name: ingress
namespace: lab
spec:
backend:
serviceName: frontend
servicePort: 80
rules:
- http:
paths:
- backend:
serviceName: backend
servicePort: 6969
path: /api
这是我部署的所有资源
NAME READY STATUS RESTARTS AGE
pod/backend-5c8c6c75bf-t4n9r 1/1 Running 0 39m
pod/frontend-75d86fb77d-6gtfs 1/1 Running 0 10m
pod/mysql-0 1/1 Running 0 30h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/backend ClusterIP 10.111.235.245 <none> 6969/TCP 150m
service/frontend ClusterIP 10.98.38.60 <none> 80/TCP 9m56s
service/mysql ClusterIP 10.107.88.14 <none> 3306/TCP 4d23h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/backend 1/1 1 1 39m
deployment.apps/frontend 1/1 1 1 10m
NAME DESIRED CURRENT READY AGE
replicaset.apps/backend-5c8c6c75bf 1 1 1 39m
replicaset.apps/frontend-75d86fb77d 1 1 1 10m
NAME READY AGE
statefulset.apps/mysql 1/1 30h
为什么它不起作用?你能和我核实一下吗?