Kubernetes (k8s) 集群,默认配置好了 Nginx Ingress 控制器,用于处理南北流量的调度,即处理从外部到集群内部服务的流量。下面是对您的架构的重新组织和概述:
这种架构允许您在 Nginx Ingress 和 APISIX 之间灵活地处理和路由流量,以满足不同的应用场景和性能要求。
外部流量首先通过 Nginx Ingress 控制器进入集群,并被路由到前端服务。前端服务处理请求后,可以将部分请求(例如 API 请求)转发到 APISIX 应用网关。APISIX 再根据其配置将流量路由到相应的后端服务(后端服务-svc),最终到达后端服务的 Pod(后端服务-pod)
apiVersion: v1
kind: Service
metadata:
name: frontend-service
spec:
selector:
app: frontend
ports:
- protocol: TCP
port: 80
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend-deployment
spec:
replicas: 2
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: your-frontend-image
ports:
- containerPort: 8080
Ingress 配置:
Copy code
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: frontend-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: "example.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
helm repo add apisix https://charts.apiseven.com
helm repo update
helm install apisix apisix/apisix --set ingress-controller.enabled=false
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: frontend-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: "example.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
- path: /api/
pathType: Prefix
backend:
service:
name: apisix-service
port:
number: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: frontend-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST, PUT, DELETE, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
spec:
rules:
- host: "example.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
- path: /api/
pathType: Prefix
backend:
service:
name: apisix-service
port:
number: 80
curl http://apisix-admin-service:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: your-api-key' \
-X PUT \
-d '{
"uri": "/api/*",
"upstream": {
"type": "roundrobin",
"nodes": {
"backend-service:80": 1
}
}
}'
请注意,您需要将 apisix-admin-service 替换为您的 APISIX 管理服务名称,your-api-key 替换为您的 API 密钥,backend-service 替换为您的后端服务名称。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。