【kubernetes】使用KubeSphere devops部署我的微服务系统

这篇具有很好参考价值的文章主要介绍了【kubernetes】使用KubeSphere devops部署我的微服务系统。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

KubeSphere Devops

入门使用KubeSphere的Devops功能部署"我的微服务系统"
(内容学习于尚硅谷云原生课程)

kubesphere devops官方文档:
https://v3-1.docs.kubesphere.io/zh/docs/devops-user-guide/how-to-use/create-a-pipeline-using-jenkinsfile/

代码准备

暂时部署这4个服务,auth服务、crm服务、gateway服务、前端ui服务

【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务
【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

Dockerfile

前端kwsphere
# 基础镜像
FROM nginx
# author
MAINTAINER kw

# 挂载目录
VOLUME /home/kw-microservices/ui/kwsphere
# 创建目录
RUN mkdir -p /home/kw-microservices/ui/kwsphere
# 指定路径
WORKDIR /home/kw-microservices/ui/kwsphere

# 复制conf文件到路径
COPY ./nginx.conf /etc/nginx/nginx.conf
# 复制html文件到路径
COPY ./dist /home/kw-microservices/ui/kwsphere

nginx配置,内容来源于ruoyi

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /home/kw-microservices/ui/kwsphere;
            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://kw-gateway:8080/;
        }

        # 避免actuator暴露
        if ($request_uri ~ "/actuator") {
            return 403;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
后端

后端这个3个服务的dockefile的内容是一样的

# 基础镜像
FROM  openjdk:8-jre
# author
MAINTAINER kw

# 挂载目录
VOLUME /home/kw-microservices
# 创建目录
RUN mkdir -p /home/kw-microservices
# 指定路径
WORKDIR /home/kw-microservices
# 复制jar文件到路径
COPY target/*.jar /home/kw-microservices/app.jar
# 启动网关服务
ENTRYPOINT ["java","-jar","app.jar"]

k8s deploy.yaml

前端kwsphere
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kwsphere
  name: kwsphere
  namespace: my-server   #一定要写名称空间
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: kwsphere
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: kwsphere
    spec:
      imagePullSecrets:
        - name: aliyun-registry-secret  #提前在项目下配置访问阿里云的账号密码
      containers:
        - image: $REGISTRY/$DOCKERHUB_NAMESPACE/kwsphere:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
#          readinessProbe:
#            httpGet:
#              path: /actuator/health
#              port: 8080
#            timeoutSeconds: 10
#            failureThreshold: 30
#            periodSeconds: 5
          imagePullPolicy: Always
          name: app
          ports:
            - containerPort: 80
              protocol: TCP
          resources:
            limits:
              cpu: 300m
              memory: 600Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: kwsphere
  name: kwsphere
  namespace: my-server
spec:
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 80
      nodePort: 31234
  selector:
    app: kwsphere
  sessionAffinity: None
  type: NodePort
后端kw-gateway
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kw-gateway
  name: kw-gateway
  namespace: my-server   #一定要写名称空间
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: kw-gateway
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: kw-gateway
    spec:
      imagePullSecrets:
        - name: aliyun-registry-secret  #提前在项目下配置访问阿里云的账号密码
      containers:
        - image: $REGISTRY/$DOCKERHUB_NAMESPACE/kw-gateway:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
#          readinessProbe:
#            httpGet:
#              path: /actuator/health
#              port: 8080
#            timeoutSeconds: 10
#            failureThreshold: 30
#            periodSeconds: 5
          imagePullPolicy: Always
          name: app
          ports:
            - containerPort: 8080
              protocol: TCP
          resources:
            limits:
              cpu: 300m
              memory: 600Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: kw-gateway
  name: kw-gateway
  namespace: my-server
spec:
  ports:
    - name: http
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app: kw-gateway
  sessionAffinity: None
  type: ClusterIP
后端kw-auth-server
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kw-auth-server
  name: kw-auth-server
  namespace: my-server   #一定要写名称空间
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: kw-auth-server
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: kw-auth-server
    spec:
      imagePullSecrets:
        - name: aliyun-registry-secret  #提前在项目下配置访问阿里云的账号密码
      containers:
        - image: $REGISTRY/$DOCKERHUB_NAMESPACE/kw-auth-server:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
#          readinessProbe:
#            httpGet:
#              path: /actuator/health
#              port: 8080
#            timeoutSeconds: 10
#            failureThreshold: 30
#            periodSeconds: 5
          imagePullPolicy: Always
          name: app
          ports:
            - containerPort: 8080
              protocol: TCP
          resources:
            limits:
              cpu: 300m
              memory: 600Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: kw-auth-server
  name: kw-auth-server
  namespace: my-server
spec:
  ports:
    - name: http
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app: kw-auth-server
  sessionAffinity: None
  type: ClusterIP
后端kw-crm-server
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kw-crm-server
  name: kw-crm-server
  namespace: my-server   #一定要写名称空间
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: kw-crm-server
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: kw-crm-server
    spec:
      imagePullSecrets:
        - name: aliyun-registry-secret  #提前在项目下配置访问阿里云的账号密码
      containers:
        - image: $REGISTRY/$DOCKERHUB_NAMESPACE/kw-crm-server:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER
#          readinessProbe:
#            httpGet:
#              path: /actuator/health
#              port: 8080
#            timeoutSeconds: 10
#            failureThreshold: 30
#            periodSeconds: 5
          imagePullPolicy: Always
          name: app
          ports:
            - containerPort: 8080
              protocol: TCP
          resources:
            limits:
              cpu: 300m
              memory: 600Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: kw-crm-server
  name: kw-crm-server
  namespace: my-server
spec:
  ports:
    - name: http
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app: kw-crm-server
  sessionAffinity: None
  type: ClusterIP

环境准备

  • 阿里云镜像服务(电脑计算资源有限,暂时使用阿里云,后续搭建harbor)
  • k8s集群
  • KubeSphere DevOps

使用Docker部署服务测试

使用k8s部署,先用docker部署一次,测试镜像和服务访问是否有问题。
本次搭建的服务镜像Dockerfile文件配置,参考若依微服务系统代码。

创建DevOps工程

【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

maven镜像地址配置

登录kubesphere管理员权限账号
在这里搜索devops
【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务
修改配置
【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务
增加maven国内镜像仓库地址配置

<mirrors>
 <mirror>  
        <id>alimaven</id>  
        <name>aliyun maven</name>  
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
        <mirrorOf>central</mirrorOf>          
 </mirror>
</mirrors>

访问凭证配置

  • gitee代码凭证
  • 阿里云镜像私有仓库访问凭证
  • k8s访问凭证
    【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

创建流水线

下图为最终的4个流水线;
先部署成功一个,后面的服务直接复制流水线,通过修改Jenkinsfile,即可快速部署服务;
【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

初学参考官方提供的流水线模板
【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

编辑流水线Jenkinsfile

SpringBoot服务

后端kw-gateway

【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

pipeline {
  agent {
    node {
      label 'maven'
    }

  }
  stages {
    stage('拉取代码') {
      agent none
      steps {
        container('maven') {
          git(url: 'https://gitee.com/kkmy/kw-microservices.git', credentialsId: 'kw-microservices-gitee', changelog: true, poll: false, branch: 'master')
          sh 'ls -l'
        }

      }
    }

    stage('项目编译打包jar') {
      agent none
      steps {
        container('maven') {
          sh 'ls -l'
          sh 'mvn clean package \'-Dmaven.test.skip=true\' -Pk8s'
        }

      }
    }

    stage('构建镜像') {
      agent none
      steps {
        container('maven') {
          sh '''ls kw-gateway/target -l
cat docker/micro-server/gateway/Dockerfile'''
          sh 'docker build -f docker/micro-server/gateway/Dockerfile -t kw-gateway:latest ./kw-gateway/'
        }

      }
    }

    stage('推送镜像') {
      agent none
      steps {
        container('maven') {
          withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,passwordVariable : 'DOCKER_ALIYUN_PWD' ,usernameVariable : 'DOCKER_ALIYUN_USER' ,)]) {
            sh 'echo "$DOCKER_ALIYUN_PWD" | docker login $REGISTRY -u "$DOCKER_ALIYUN_USER" --password-stdin'
            sh 'docker tag kw-gateway:latest  $REGISTRY/$DOCKERHUB_NAMESPACE/kw-gateway:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
            sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/kw-gateway:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
          }

        }

      }
    }

    stage('部署dev环境') {
      agent none
      steps {
        container ('maven') {
                      withCredentials([
                          kubeconfigFile(
                          credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
                          variable: 'KUBECONFIG')
                          ]) {
                          sh 'envsubst < deploy/gateway/deploy.yaml | kubectl apply -f -'
                      }
                 }
      }
    }

  }
  environment {
    DOCKER_CREDENTIAL_ID = 'dockerhub-id'
    GITHUB_CREDENTIAL_ID = 'github-id'
    KUBECONFIG_CREDENTIAL_ID = 'kubeconfig'
    REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
    DOCKERHUB_NAMESPACE = 'kk_hub'
    GITHUB_ACCOUNT = 'kubesphere'
    APP_NAME = 'kw-gateway'
  }
  parameters {
    string(name: 'TAG_NAME', defaultValue: '', description: '')
  }
}
后端kw-crm-server

【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

pipeline {
  agent {
    node {
      label 'maven'
    }

  }
  stages {
    stage('拉取代码') {
      agent none
      steps {
        container('maven') {
          git(url: 'https://gitee.com/kkmy/kw-microservices.git', credentialsId: 'kw-microservices-gitee', changelog: true, poll: false, branch: 'master')
          sh 'ls -l'
        }

      }
    }

    stage('项目编译打包jar') {
      agent none
      steps {
        container('maven') {
          sh 'ls -l'
          sh 'mvn clean package \'-Dmaven.test.skip=true\' -Pk8s'
        }

      }
    }

    stage('构建镜像') {
      agent none
      steps {
        container('maven') {
          sh '''ls kw-modules/kw-crm-service/target -l
cat docker/micro-server/crm-server/Dockerfile'''
          sh 'docker build -f docker/micro-server/crm-server/Dockerfile -t kw-crm-server:latest ./kw-modules/kw-crm-service/'
        }

      }
    }

    stage('推送镜像') {
      agent none
      steps {
        container('maven') {
          withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,passwordVariable : 'DOCKER_ALIYUN_PWD' ,usernameVariable : 'DOCKER_ALIYUN_USER' ,)]) {
            sh 'echo "$DOCKER_ALIYUN_PWD" | docker login $REGISTRY -u "$DOCKER_ALIYUN_USER" --password-stdin'
            sh 'docker tag kw-crm-server:latest  $REGISTRY/$DOCKERHUB_NAMESPACE/kw-crm-server:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
            sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/kw-crm-server:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
          }

        }

      }
    }

    stage('部署dev环境') {
      agent none
      steps {
        container('maven') {
          withCredentials([
                                                  kubeconfigFile(
                                                      credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
                                                      variable: 'KUBECONFIG')
                                                      ]) {
                sh 'envsubst < deploy/crm-server/deploy.yaml | kubectl apply -f -'
              }

            }

          }
        }

      }
      environment {
        DOCKER_CREDENTIAL_ID = 'dockerhub-id'
        GITHUB_CREDENTIAL_ID = 'github-id'
        KUBECONFIG_CREDENTIAL_ID = 'kubeconfig'
        REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
        DOCKERHUB_NAMESPACE = 'kk_hub'
        GITHUB_ACCOUNT = 'kubesphere'
        APP_NAME = 'kw-crm-server'
      }
      parameters {
        string(name: 'TAG_NAME', defaultValue: '', description: '')
      }
    }
后端kw-auth-server

【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

pipeline {
  agent {
    node {
      label 'maven'
    }

  }
  stages {
    stage('拉取代码') {
      agent none
      steps {
        container('maven') {
          git(url: 'https://gitee.com/kkmy/kw-microservices.git', credentialsId: 'kw-microservices-gitee', changelog: true, poll: false, branch: 'master')
          sh 'ls -l'
        }

      }
    }

    stage('项目编译打包jar') {
      agent none
      steps {
        container('maven') {
          sh 'ls -l'
          sh 'mvn clean package \'-Dmaven.test.skip=true\' -Pk8s'
        }

      }
    }

    stage('构建镜像') {
      agent none
      steps {
        container('maven') {
          sh '''ls kw-auth/kw-auth-server/target -l
cat docker/micro-server/auth-server/Dockerfile'''
          sh 'docker build -f docker/micro-server/auth-server/Dockerfile -t kw-auth-server:latest ./kw-auth/kw-auth-server/'
        }

      }
    }

    stage('推送镜像') {
      agent none
      steps {
        container('maven') {
          withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,passwordVariable : 'DOCKER_ALIYUN_PWD' ,usernameVariable : 'DOCKER_ALIYUN_USER' ,)]) {
            sh 'echo "$DOCKER_ALIYUN_PWD" | docker login $REGISTRY -u "$DOCKER_ALIYUN_USER" --password-stdin'
            sh 'docker tag kw-auth-server:latest  $REGISTRY/$DOCKERHUB_NAMESPACE/kw-auth-server:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
            sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/kw-auth-server:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
          }

        }

      }
    }

    stage('部署dev环境') {
      agent none
      steps {
        container ('maven') {
                      withCredentials([
                          kubeconfigFile(
                          credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
                          variable: 'KUBECONFIG')
                          ]) {
                          sh 'envsubst < deploy/auth-server/deploy.yaml | kubectl apply -f -'
                      }
                 }
      }
    }

  }
  environment {
    DOCKER_CREDENTIAL_ID = 'dockerhub-id'
    GITHUB_CREDENTIAL_ID = 'github-id'
    KUBECONFIG_CREDENTIAL_ID = 'kubeconfig'
    REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
    DOCKERHUB_NAMESPACE = 'kk_hub'
    GITHUB_ACCOUNT = 'kubesphere'
    APP_NAME = 'kw-auth-server'
  }
  parameters {
    string(name: 'TAG_NAME', defaultValue: '', description: '')
  }
}

Nodejs服务

前端kwsphere

【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

pipeline {
  agent {
    node {
      label 'nodejs'
    }

  }
  stages {
    stage('拉取代码') {
      agent none
      steps {
        container('nodejs') {
          git(url: 'https://gitee.com/kkmy/kw-microservices.git', credentialsId: 'kw-microservices-gitee', changelog: true, poll: false, branch: 'master')
          sh 'ls kw-ui/kwsphere -l'
        }

      }
    }

    stage('项目编译dist') {
      agent none
      steps {
        container('nodejs') {
          sh 'npm config set user 0'
          sh 'npm config set unsafe-perm true'
          sh 'npm uninstall node-sass'
          sh 'npm i node-sass@4.14.1 --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ --unsafe-perm'
          sh 'npm install --prefix ./kw-ui/kwsphere --registry=https://registry.npm.taobao.org'
          sh 'npm --prefix ./kw-ui/kwsphere run build:prod'
          sh 'ls -l'
        }

      }
    }

    stage('构建镜像') {
      agent none
      steps {
        container('nodejs') {
          sh 'cat docker/micro-server/ui/Dockerfile'
          sh 'docker build -f docker/micro-server/ui/Dockerfile -t kwsphere:latest ./kw-ui/kwsphere/'
        }

      }
    }

    stage('推送镜像') {
      agent none
      steps {
        container('nodejs') {
          withCredentials([usernamePassword(credentialsId : 'aliyun-docker-registry' ,passwordVariable : 'DOCKER_ALIYUN_PWD' ,usernameVariable : 'DOCKER_ALIYUN_USER' ,)]) {
            sh 'echo "$DOCKER_ALIYUN_PWD" | docker login $REGISTRY -u "$DOCKER_ALIYUN_USER" --password-stdin'
            sh 'docker tag kwsphere:latest  $REGISTRY/$DOCKERHUB_NAMESPACE/kwsphere:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
            sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/kwsphere:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
          }

        }

      }
    }

    stage('部署dev环境') {
      agent none
      steps {
        container('nodejs') {
          withCredentials([
                                                                                                              kubeconfigFile(
                                                                                                                            credentialsId: env.KUBECONFIG_CREDENTIAL_ID,
                                                                                                                            variable: 'KUBECONFIG')
                                                                                                                            ]) {
                sh 'envsubst < deploy/kwsphere/deploy.yaml | kubectl apply -f -'
              }

            }

          }
        }

      }
      environment {
        DOCKER_CREDENTIAL_ID = 'dockerhub-id'
        GITHUB_CREDENTIAL_ID = 'github-id'
        KUBECONFIG_CREDENTIAL_ID = 'kubeconfig'
        REGISTRY = 'registry.cn-hangzhou.aliyuncs.com'
        DOCKERHUB_NAMESPACE = 'kk_hub'
        GITHUB_ACCOUNT = 'kubesphere'
        APP_NAME = 'kwsphere'
      }
      parameters {
        string(name: 'TAG_NAME', defaultValue: '', description: '')
      }
    }

问题记录

Kubernetes Deploy插件问题

尚硅谷教程中的k8s deploy插件运行没问题,但在目前搭建过程中不好使了,会报错;

#没有找到
Starting Kubernetes deployment
Loading configuration: /home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere-ui/deploy/gateway/deploy.yml
ERROR: ERROR: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException: Bad Request

 "message": "the export parameter, deprecated since v1.14, is no longer supported",

【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务

问了kubespere群中的大佬,说是该插件已废弃,官网有新示例。

就是不能再用这个插件了
【kubernetes】使用KubeSphere devops部署我的微服务系统,# KubeSphere,kubernetes,devops,微服务
改用shell命令运行

sh 'envsubst < deploy/kwsphere/deploy.yaml | kubectl apply -f -'

service指定nodeport报错

#k8s指定端口报错
The Service "kwsphere" is invalid: spec.ports[0].nodePort: Invalid value: 43113: provided port is not in the valid range. The range of valid ports is 30000-32767

前端服务build报错

#npm install报错
#解决,install之前,运行这两个命令
npm config set user 0 
npm config set unsafe-perm true

Unable to save binary /home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere/kw-ui/kwsphere/node_modules/node-sass/vendor/linux-x64-64 : { Error: EACCES: permission denied, mkdir '/home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere/kw-ui/kwsphere/node_modules/node-sass/vendor'
    at Object.mkdirSync (fs.js:757:3)
    at sync (/home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere/kw-ui/kwsphere/node_modules/mkdirp/index.js:74:13)
    at Function.sync (/home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere/kw-ui/kwsphere/node_modules/mkdirp/index.js:80:24)
    at checkAndDownloadBinary (/home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere/kw-ui/kwsphere/node_modules/node-sass/scripts/install.js:114:11)
    at Object.<anonymous> (/home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere/kw-ui/kwsphere/node_modules/node-sass/scripts/install.js:157:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path:
   '/home/jenkins/agent/workspace/kw-devopsw2gh4/kubesphere/kw-ui/kwsphere/node_modules/node-sass/vendor' }
#又报错,解决:流水线 步骤中添加执行如下命令
#npm uninstall node-sass
#npm i node-sass@4.14.1 --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ --unsafe-perm

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.14.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-08-27T08_57_22_270Z-debug.log
script returned exit code 1

代码多目录build node.js服务问题

我的前后端代码在一个工程中,导致在运行npm命令,找不到package.json文件
尝试在构建过程中,先执行cd命令,进入到前端代码的目录下,但是不好使,
最后找到npm命令如何指定package.json文件路径解决

#使用--prefix参数
npm install --prefix ./kw-ui/kwsphere --registry=https://registry.npm.taobao.org
npm --prefix ./kw-ui/kwsphere run build:prod

结语

以上仅仅是入门学习使用,devops流水线,还有很多地方可以简化配置文章来源地址https://www.toymoban.com/news/detail-685932.html

到了这里,关于【kubernetes】使用KubeSphere devops部署我的微服务系统的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Kubernetes部署+kubesphere管理平台安装

    Kubernetes官网;kubesphere官网           不论是Kubernetes官网还是找的其它部署步骤,基本都是推荐搭建集群的方式,是为了实现高可用.....等等,这样一来至少需要两台或三台的服务器来搭建,这样对我们的成本也是非常大的,所以我就尝试了用一台机器来部署,下面是具体

    2024年02月15日
    浏览(36)
  • kubernetes(k8s)+kubesphere部署

    目录 一 装备三台机器linux(centos) 二 准备前置环境并安装kubernetes 1  三台机器都要做如下操作  1.1 关闭防火墙: 1.2 关闭 selinux: 1.3 关闭 swap 1.4 添加主机名与 IP 对应关系 1.5 date 查看时间 (可选) 1.6 卸载系统之前的 docke 命令自行百度不做说明 1.7 安装 Docker-CE  1. 7.1 装

    2024年01月17日
    浏览(71)
  • 【业务功能115】微服务-springcloud-springboot-Kubernetes-k8s集群-Kubesphere实现DevOps流水线-CI/CD-SonarQube- Jenkins

    dev 怎么开发 ops 怎么运维 参考项目链接:https://github.com/kubesphere/devops-maven-sample 持续集成是指软件个人的部分向软件整体部分交付,频繁进行集成以便更快地发现其中错误。 CI需要具备这些: 全面的自动化测试 这是实践持续集成持续部署的基础,同时,选择合适的自动化测

    2024年02月04日
    浏览(86)
  • kubesphere多集群管理,实现kubernetes多集群同时应用部署

    测试kubesphere多集群管理功能,至少需要两套kubesphere集群环境。 1、准备环境 执行以下命令,集群的节点都需要执行。 2、下载kubesphere安装工具KubeKey 这里我先下载好安装工具,在部署操作系统上进行解压,解压出来就具有了 kk 命令。如果没有执行权限,执行如下命令。 3、准

    2024年02月06日
    浏览(44)
  • 云原生|kubernetes|离线化部署kubesphere(从网络插件开始记录)

    kubesphere的离线化部署指的是通过自己搭建的harbor私有仓库拉取镜像,完全不依赖于外部网络的方式部署。 我的kubernetes集群是一个单master节点,双工作节点,总计三个节点的版本为1.22.16的集群。 该集群只是初始化完成了,网络插件什么的都还没有安装,本文计划做一个整合

    2024年02月11日
    浏览(74)
  • 云原生|kubernetes|centos7下的kubeadm部署的集群内在线部署kubesphere(外部etcd)

    本文将主要就在centos7操作系统下已有的一个利用kubeadm部署的集群内在线安装kubesphere做一个介绍,该kubernetes集群是使用的etcd外部集群。 kubernetes集群的搭建本文不做过多介绍,具体的搭建流程见我的博客: 云原生|kubernetes|kubeadm部署高可用集群(一)使用外部etcd集群_kubeadm

    2024年02月11日
    浏览(44)
  • DevOps搭建(十五)-kubernetes部署项目详细步骤

    k8s官网地址 https://kubernetes.io/zh-cn/docs/home/ 详细步骤可参考官网 https://kuboard.cn/install/install-k8s.html 至少 2 台 2核4G 的服务器。 选择v1.19,因为高版本的已经把docker给舍弃掉了。 https://kuboard.cn/install/history-k8s/install-k8s-1.19.x.html 主机执行 从机执行 主机和从机都要执行 2.4.1、执行初

    2024年01月17日
    浏览(40)
  • 云原生|kubernetes|centos7下离线化部署kubesphere-3.3.2---基于kubernetes-1.22.16(从网络插件开始记录)

    kubesphere的离线化部署指的是通过自己搭建的harbor私有仓库拉取镜像,完全不依赖于外部网络的方式部署。 我的kubernetes集群是一个单master节点,双工作节点,总计三个节点的版本为1.22.16的集群。 该集群只是初始化完成了,网络插件什么的都还没有安装,本文计划做一个整合

    2024年02月12日
    浏览(41)
  • 【业务功能118】微服务-springcloud-springboot-Kubernetes集群-k8s集群-KubeSphere-OpenELB部署及应用

    网址: openelb.io OpenELB 是一个开源的云原生负载均衡器实现,可以在基于裸金属服务器、边缘以及虚拟化的 Kubernetes 环境中使用 LoadBalancer 类型的 Service 对外暴露服务。OpenELB 项目最初由 KubeSphere 社区发起,目前已作为 CNCF 沙箱项目加入 CNCF 基金会,由 OpenELB 开源社区维护与支

    2024年02月03日
    浏览(96)
  • 基于Kubesphere实现DevOps

    dev 怎么开发 ops 怎么运维 参考项目链接:https://github.com/kubesphere/devops-maven-sample 持续集成是指软件个人的部分向软件整体部分交付,频繁进行集成以便更快地发现其中错误。 CI需要具备这些: 全面的自动化测试 这是实践持续集成持续部署的基础,同时,选择合适的自动化测

    2024年02月08日
    浏览(28)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包