微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过 NGINX INGRESS 和文件类型公开 Kubernetes 服务时出错:LoadBalancer

如何解决通过 NGINX INGRESS 和文件类型公开 Kubernetes 服务时出错:LoadBalancer

我有一个使用 Docker 构建的 Vuejs 应用程序,使用 Nginx 分 2 个阶段构建:


# estágio de compilação 

FROM node:10-alpine as build-stage 

workdir /app 

ARG VUE_APP_BASE_URL="minha-base-url" 

ENV VUE_APP_BASE_URL=${VUE_APP_BASE_URL} 

copY package*.json ./ 

RUN npm install 

copY . . 

RUN npm run build 

 
 

# estágio de produção 

FROM Nginx:stable-alpine as production-stage 

copY --from=build-stage /app/dist /usr/share/Nginx/html 

copY --from=build-stage /app/Nginx.conf /etc/Nginx/conf.d/Nginx.conf 

EXPOSE 80 

CMD ["Nginx","-g","daemon off;"] 

 

Nginx.conf


server {

  listen 80; 

  location / {
    alias /app/dist;
    index index.html index.htm;
    try_files $uri $uri/ @rewrites;
  }
  
  location @rewrites {
   rewrite ^.$ /index.html last;
  }

  error_page   500 502 503 504  /50x.html;

  location = /50x.html {
    root   /usr/share/Nginx/html;
  }
}

通过触发 docker run 命令一切正常。当升级到 kubernetes 时,使用 port-forward 一切正常:


kubectl port-forward deployment/app-front 8082:80 

最大的问题是,当我使用 1-type:LoadBalancer 创建服务时,我无法通过生成的外部 IP 访问应用程序,2- 同样,当我尝试通过 Nginx INGRESS 时,它会给出错误 503。注意:我还有其他在上面提到的这两种情况下完美运行的服务,但这些其他应用程序不是建立在 docker 上的 Nginx 映像之上,所以我怀疑错误可能由于某些冲突来自那里,但我无法得出具体结论。以下是文件

应用前端部署


apiVersion: apps/v1
kind: Deployment
Metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: app-front
  name: app-front
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: app-front
      app: app-front
  strategy: {}
  template:
    Metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.22.0 (955b78124)
      creationTimestamp: null
      labels:
        io.kompose.service: app-front
        app: app-front
    spec:
      containers:
        - image: fabiomdsdj/agendime-front:0.0.3
          name: app-front
          ports:
            - containerPort: 8082
              name: http
          env:
          - name: VUE_APP_BASE_URL
            value: "app"
          resources: {}
      restartPolicy: Always
status: {}


App-front-service.yaml:


apiVersion: v1
kind: Service
Metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: app-front
  name: app-front
spec:
  type: ClusterIP
  ports:
    - name: "8082"
      port: 8082
      targetPort: 8082
  selector:
    io.kompose.service: app-front
    app: app-front
    tier: app-front
 

App-front-ingress.yaml:


apiVersion: networking.k8s.io/v1
kind: Ingress
Metadata:
  name: app-ingress
  annotations:
    kubernetes.io/ingress.class: Nginx
    Nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: "app.agendi.me"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: app-front
            port:
              number: 8082

我已经头昏脑胀好几天了,找不到解决办法,有人可以帮帮我吗?

注意:通过这些相同的配置,我可以公开我拥有的其他服务。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。