简体   繁体   English

使用 ingress-nginx 在 kube.netes 中提供 static 个资产

[英]Serving static assets in kubernetes with ingress-nginx

I have a Pod that contains an image of a NodeJS project serving a build of vuejs (Manual SSR) And I have an ingress controller to match a host to the service connecting to the Pod as follows:我有一个 Pod,其中包含服务于 vuejs(手动 SSR)构建的 NodeJS 项目的图像,并且我有一个入口 controller 以将主机与连接到 Pod 的服务相匹配,如下所示:

在此处输入图像描述

The Problem I'm facing is that static assets (CSS, JS and images) aren't served, so they need a "server" that handles these files.我面临的问题是没有提供 static 资产(CSS、JS 和图像),因此他们需要一个“服务器”来处理这些文件。

I tried to have the Pod mounts two containers, NodeJS + Nginx container and copy the static file in Nginx /var/www/html and serve them from there using nginx location rule but it looks like an overkill to put that in production.我试图让 Pod 安装两个容器,NodeJS + Nginx 容器并将 static 文件复制到 Nginx /var/www/html 并使用nginx location rule从那里为它们提供服务,但将其投入生产看起来有点矫枉过正。

I'm curious how the best way to do this, maybe using Ingress controller rules/annotations?我很好奇最好的方法是如何做到这一点,也许使用 Ingress controller 规则/注释? or some way that I am missing?或者我想念的某种方式?

My Ingress controller looks like:我的 Ingress controller 看起来像:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: test.ssr.local
      http:
        paths:
          - path: /
            backend:
              serviceName: service-internal-ssr
              servicePort: 8080

My Deployment looks like:我的部署看起来像:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ssr
spec:
  selector:
    matchLabels:
      app: ssr
  template:
    metadata:
      labels:
        app: ssr
    spec:
        - name: ssr
          image: ...
          resources:
            limits:
              cpu: 0.5
              memory: 1000Mi
            requests:
              cpu: 0.2
              memory: 500Mi
          ports:
            - name: app-port
              containerPort: 2055
---
apiVersion: v1
kind: Service
metadata:
  name: service-internal-ssr
spec:
  type: ClusterIP
  selector:
    app: ssr
  ports:
    - port: 8080
      targetPort: 2055

Thank you in advance先感谢您

I would suggest serving your static content from something like a bucket or CDN, something as close to the client as possible that is better suited for this use case.我建议从存储桶或 CDN 之类的东西提供您的 static 内容,这些东西尽可能靠近客户端,更适合这种用例。 Using K8s for this is overkill.为此使用 K8s 是矫枉过正的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kube.netes - Ingress-nginx 路由错误(无法将前端连接到后端) - Kubernetes - Ingress-nginx routing error (Cannot connect frontend to backend) webpack react ingress-nginx kubernetes 显示网关错误 - webpack react ingress-nginx kubernetes shows Bad Gateway nginx 不为 ingress-nginx 后面的 PHP 应用程序提供 JS、CSS 文件 - nginx not serving JS, CSS files for PHP app behind ingress-nginx 使用Nginx,Kubernetes和Docker服务资产 - Serving assets using nginx, kubernetes and docker 如何安装“ingress-nginx”? - How to install "ingress-nginx"? 当 kubernetes ingress-nginx 在 docker windows 上运行时,找不到 404 页面 - 404 page not found when kubernetes ingress-nginx is run on docker windows 如何使用 Docker 桌面为 Windows Kube.netes 和 ingress-nginx 公开 postgres tcp 端口 - How to expose postgres tcp port using Docker Desktop for Windows Kubernetes and ingress-nginx Kubernetes ingress-nginx从非默认命名空间调用服务 - Kubernetes ingress-nginx call service from non-default namespace 在 Kubernetes 上使用 nginx 和 gunicorn 为 Django 静态文件提供服务 - serving Django static files with nginx and gunicorn on kubernetes 在 Window 上安装 ingress-nginx 的问题(不是 minikube) - Issue with install ingress-nginx on Window (Not minikube)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM