k8s离线部署芋道源码前端

概述

   本篇将对 k8s离线部署芋道源码前端 进行详细的说明,对如何构建 Dockerfile,如何整合 Nginx,如何整合 ingress 进行实践。

   相关文章:nacos在k8s上的集群安装实践

  效果如下(电脑只8G内存,所以演示较卡):

k8s离线部署芋道源码前端

编译

先将前端源码进行编译

npm run build:prod

在这里插入图片描述

Dockerfile 构建

结构目录如下:
在这里插入图片描述

Dockerfile

FROM harbor.easzlab.io.local:8443/library/nginx:stable-alpine3.19-perl

# 将 Vue 项目的打包文件复制到 Nginx 静态文件目录下
COPY dist/ /usr/share/nginx/html/

# 复制自定义的 Nginx 配置文件到容器中
COPY nginx.conf /etc/nginx/conf.d/default.conf

# 暴露容器的 80 端口
EXPOSE 80

# 容器启动时执行的命令
CMD ["nginx", "-g", "daemon off;"]

nginx.conf

server {
    listen 80;
    server_name localhost;

    location / {
        root   /usr/share/nginx/html/;
        try_files $uri $uri/ /index.html;
        index  index.html index.htm;
    }
    location /prod-api/{
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://gateway.default.svc.cluster.local:48080/;
    }
    # 避免actuator暴露
    if ($request_uri ~ "/actuator") {
        return 403;
    }
    error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
    }
}

构建

先构建镜像,再上传至私服。

docker build -t fun-vue/fun-vue:1.0.0 .
docker tag fun-vue/fun-vue:1.0.0 harbor.easzlab.io.local:8443/library/fun-vue:1.0.0
docker push  harbor.easzlab.io.local:8443/library/fun-vue:1.0.0

在这里插入图片描述

k8s部署

前端镜像部署

vue-dp.yaml


apiVersion: apps/v1
kind: Deployment
metadata:
  name: vue
spec:
  # 根据需求设置副本数量
  replicas: 1
  selector:
    matchLabels:
      app: vue
  template:
    metadata:
      labels:
        app: vue
    spec:
      containers:
      - name: vue
        image: harbor.easzlab.io.local:8443/library/fun-vue:1.0.0
        imagePullPolicy: Always
        ports:
        - containerPort: 80
          name: http
        - containerPort: 443
          name: https


---
# 创建Pod的Service
apiVersion: v1
kind: Service
metadata:
  name: vue-svc
  namespace: default
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: vue

在这里插入图片描述

ingress


#ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-all
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
#    kubernetes.io/ingress.class: nginx
spec:
  ingressClassName: nginx
  rules:
  - host: "all.fun.com"
    http:
      paths:
        - pathType: Prefix
          path: /
          backend:
            service:
              name: openresty-svc
              port:
                number: 80

相关推荐

  1. k8s线部署后端

    2024-07-10 19:28:03       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 19:28:03       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 19:28:03       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 19:28:03       90 阅读
  4. Python语言-面向对象

    2024-07-10 19:28:03       98 阅读

热门阅读

  1. 最小生成树(算法篇)

    2024-07-10 19:28:03       27 阅读
  2. K8S集群应用国产信创适配实战经验总结

    2024-07-10 19:28:03       24 阅读
  3. 方程与不等式

    2024-07-10 19:28:03       28 阅读
  4. 力扣1472.设计浏览器历史记录

    2024-07-10 19:28:03       26 阅读
  5. ArcGIS Pro SDK (八)地理数据库 3 数据

    2024-07-10 19:28:03       25 阅读
  6. C语言 找出一个二维数组中的鞍点

    2024-07-10 19:28:03       26 阅读
  7. [目标检测]labelme标注数据转yoloV8需要的.txt格式

    2024-07-10 19:28:03       27 阅读
  8. ES6 之 Promise 构造函数知识点总结 (四)

    2024-07-10 19:28:03       29 阅读
  9. 软件工程需求之:业务需求与用户需求

    2024-07-10 19:28:03       21 阅读