• 【四】将vue部署到k8s中


    准备dockerfile和jenkinsfile还有yml文件

    因为我前三步将其他的都弄好了,我现在的目的只是为了简单部署上去,所以没做其他深入研究配置,我的简单代码:https://gitee.com/feiminjie/helloworldfront
    
    • 1
    我准备的dockerfile
    # 使用官方 Node.js 镜像
    FROM node:14
    # 设置工作目录
    WORKDIR /appf
    # 将项目文件复制到容器中
    COPY . .
    # 安装项目依赖
    RUN npm install
    # 构建生产环境
    RUN npm run build
    # 暴露端口
    EXPOSE 80
    # 启动应用
    CMD ["npm", "run", "start"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    我准备的Jenkinsfile

    // 所有的脚本命令都放在当前的pipline中
    pipeline{
    	// 制定任务在哪个集群节点中执行
    	agent any
    	
    	// 声明全局变量,方便后面使用
    	environment {
    		key = 'value'
    	}
    	
    	stages {
            	stage('拉取git仓库代码') {
                		steps {
    checkout scmGit(branches: [[name: '${tag}']], extensions: [], userRemoteConfigs: [[credentialsId: 'ee882b26-32f7-487f-af8b-8ce97ae6d923', url: 'https://gitee.com/feiminjie/helloworldfront.git']])
                }
            }
                 stage('生成docker镜像') {
                		steps {
                		sh 'docker build -t hellofront:$tag .'
                }
            }
                stage('推送harbor') {
                		steps {
                		    sh '''docker login -u admin -p Harbor12345 103.39.222.98:80
    docker tag hellofront:$tag 103.39.222.98:80/hellofront/hellofront:$tag
    docker push 103.39.222.98:80/hellofront/hellofront:$tag'''
                		}
            	}
                stage('推送yml到master') {
                		steps {
                		    sshPublisher(publishers: [sshPublisherDesc(configName: 'k8s', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'pipefront.yml')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
                		}
            	}
            	stage('执行yml文件') {
                		steps {
                		sh '''ssh root@103.39.226.71 kubectl apply -f /usr/local/k8s/pipefront.yml
    ssh root@103.39.226.71 kubectl rollout restart deployment helloworldfront-deployment -n front'''
                		}
            	}
         }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    里面配置和后端写的区分开就行了

    我准备的 front.yml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      namespace: front
      name: helloworldfront-deployment
      labels:
        app: helloworldfront-deployment
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: helloworldfront
      template:
        metadata:
          labels:
            app: helloworldfront
        spec:
          containers:
          - name: helloworldfront
            image: 103.39.222.98:80/hellofront/hellofront:v4.0.0
            imagePullPolicy: Always
            ports:
            - containerPort: 80
          imagePullSecrets:
            - name: harbor-token
    ---
    apiVersion: v1
    kind: Service
    metadata:
      namespace: front
      name: helloworldfront-deployment
      labels:
        app: helloworldfront-deployment
    spec:
      selector:
        app: helloworldfront
      ports:
      - port: 80
        targetPort: 80
      type: NodePort
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      labels:
        app: helloworldfront-deployment
        k8s.kuboard.cn/name: helloworldfront-deployment
      name: helloworldfront-deployment
      namespace: front
    spec:
      defaultBackend:
        service:
          name: helloworldfront-deployment
          port:
            number: 80
      ingressClassName: ingress
      rules:
        - host: bomj.shop
          http:
            paths:
              - backend:
                  service:
                    name: helloworldfront-deployment
                    port:
                      number: 80
                path: /
                pathType: Prefix
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69

    kuboard配置

    1、创建上面yml文件中的命名空间
    2、在front命名空间内创建密文

    步骤都和前面三步中的步骤差不多,如果有什么报错对着日志改一改就可以了。

    任意节点+端口就可以访问了
    在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    虚拟机安装CentOS7教程
    【AntDesign】封装全局异常处理-全局拦截器
    MySQL安装
    进程地址空间
    黑猫带你学UFS协议第22篇:UFS语境管理详解(context management)
    k8s docker 中部署think php 并搭建php websocket
    C# 使用Microsoft.Office.Interop.Excel库操作Excel
    notepad++怎么运行以及配置
    电脑系统数据恢复哪个好?万兴恢复专家-支持各种场景的数据恢复
    202435读书笔记|《半小时漫画中国史》——读点经济学与历史,生活更美好,趣味烧脑土地制度、商鞅变法、华丽丽的丝绸之路这里都有
  • 原文地址:https://blog.csdn.net/weixin_42916710/article/details/136677612