I have a small java webapp comprising of three microservices - api-service,book-service and db-service all of which are deployed on a kubernetes cluster locally using minikube.
I am planning to keep separate UIs for api-service and book-service , with the common static files served from a separate pod, probably an nginx:alpine
image.
I was able to create a front end that serves the static files from nginx:alpine
referring to this tutorial.
I would like to use ingress-nginx
controller for routing requests to the two services.
The below diagram crudely shows where I am now.
I am confused as to where I should place the pod that serves the static content, and how to connect it to the ingress resource.I guess that keeping a front end pod before ingress defeats the purpose of ingress-nginx controller. What is the best practice to serve static files. Appreciate any help. Thanks.
答案 0 :(得分:2)
您似乎对以下事实感到困惑:在线浏览的用户会触发标准请求,以“下载”您的静态内容,和使用您的2个API(book和api)。访问您的API的不是提供静态内容的NGINX服务,而是用户的浏览器/应用程序,它们对静态内容和API完全相同(前者具有更多/特定的标头和数据,例如auth ... )。
在图表上,您希望将新的static-service
与book-service
和api-service
放置在完全相同的级别,即在后面。但是您的static-service
将不会像其他db-service
那样与apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: your-global-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: foo.bar.com
http:
paths:
- path: /book-service
backend:
serviceName: book-service
servicePort: 80
- path: /api-service
backend:
serviceName: api-service
servicePort: 80
- path: /
backend:
serviceName: static-service
servicePort: 80
链接。然后只需完成您的入口规则,并在本例中最后添加static-service:
foo.bar.com/book-service
在上面的示例中,您必须调整服务名称和端口,并选择希望用户访问API的路径:
foo.bar.com/api-service
用于您的图书服务foo.bar.com/
用于api服务
frame = camera.get_frame()
frame_data = unicode(frame, "utf-8")
,即其他所有要用于静态服务的内容答案 1 :(得分:0)
您应该拥有3个不同的豆荚: - 静态的 -图书服务 -API服务
静态吊舱极有可能无法以彼此相同的速度缩放。
为每个部署创建服务。然后使用ingres在正确的端点上路由流量。
是您想要实现的目标吗?