kubesphere中搭建DevOps创建流水线
kubesphere中搭建DevOps创建流水线
前提条件
●已有一个可用的企业空间(非 system-workspace)。
●您需要加入一个企业空间并在企业空间中具有 DevOps 项目创建权限
●KubeSphere 平台需要安装并启用 DevOps 扩展组件
●做一个构建用的镜像,镜像包括git,go,nerdctl(环境用的是containerd没有用docker),做出来之后放到镜像仓库,地址:https://registry.cn-shenzhen.aliyuncs.com/youli371966511/go-build:2.0.0
1.启用DevOps组件
ps:
1.DevOps需要存储卷,可以提前创建存储卷,再把pvc绑定到pv
2.创建账号企业空间、角色、账号
1.创建角色
2.编辑角色权限
3.授权对应权限
4.添加用户
5.创建企业空间
6.邀请成员
2.修改jenkins_casc_config
1.找到jenkins_casc_config配置字典点击修改yaml
2.添加配置
- name: "gobuild2"namespace: "kubesphere-devops-worker"label: "gobuild2"nodeUsageMode: "EXCLUSIVE"idleMinutes: 0containers:- name: "go"image: "registry.cn-shenzhen.aliyuncs.com/youli371966511/go-build:2.0.0"command: "cat"args: ""ttyEnabled: trueprivileged: trueresourceRequestCpu: "100m"resourceLimitCpu: "4000m"resourceRequestMemory: "100Mi"resourceLimitMemory: "8192Mi"- name: "jnlp"image: "swr.cn-southwest-2.myhuaweicloud.com/ks/jenkins/inbound-agent:4.10-2"args: "^${computer.jnlpmac} ^${computer.name}"resourceRequestCpu: "50m"resourceLimitCpu: "500m"resourceRequestMemory: "400Mi"resourceLimitMemory: "1536Mi"workspaceVolume:emptyDirWorkspaceVolume:memory: falsevolumes:- hostPathVolume:hostPath: "/var/run/containerd/containerd.sock"mountPath: "/var/run/containerd/containerd.sock"- hostPathVolume:hostPath: "/var/data/jenkins_go_cache"mountPath: "/home/jenkins/go/pkg"- hostPathVolume:hostPath: "/var/data/jenkins_sonar_cache"mountPath: "/root/.sonar/cache"yaml: |spec:activeDeadlineSeconds: 21600affinity:nodeAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 1preference:matchExpressions:- key: node-role.kubernetes.io/workeroperator: Invalues:- citolerations:- key: "node.kubernetes.io/ci"operator: "Exists"effect: "NoSchedule"- key: "node.kubernetes.io/ci"operator: "Exists"effect: "PreferNoSchedule"containers:- name: "go"resources:requests:ephemeral-storage: "1Gi"limits:ephemeral-storage: "10Gi"securityContext:fsGroup: 1000
3.创建流水线
1.创建devops项目
2.进入note-golang项目创建凭证
3.创建流水线
4.编辑流水线(编辑Jenkinsfile)
pipeline {agent {node {label 'gobuild2'}}stages {stage('pull') {agent nonesteps {container('go') {git(url: 'https://gitee.com/youliroam/pm-be.git', credentialsId: 'gitee-id', branch: 'master', changelog: true, poll: false)sh 'ls -lh'}}}stage('build') {agent nonesteps {container('go') {sh 'export GOPROXY=https://goproxy.cn'sh 'go mod tidy'sh 'pwd'sh 'ls -lh'sh 'go build -o main main.go'}}}stage('pack') {agent nonesteps {container('go') {sh 'buildctl --version'sh 'buildkitd &'sh 'nerdctl build -t registry.cn-shenzhen.aliyuncs.com/youli371966511/pm-go:v1.0.1 .'sh 'ls -lh'}}}stage('push') {agent nonesteps {container('go') {withCredentials([usernamePassword(credentialsId: 'aliyun-images-id', passwordVariable: 'PASSWD', usernameVariable: 'USER')]) {sh 'echo "$PASSWD" | nerdctl login --username "$USER" --password-stdin $REGISTRY'sh 'nerdctl push registry.cn-shenzhen.aliyuncs.com/youli371966511/pm-go:v1.0.1'}}}}}environment {REPO_URL = 'https://gitee.com/youliroam/zbn_note.git'BRANCH = 'master'GOPROXY = 'https://goproxy.cn,direct'REGISTRY = 'registry.cn-shenzhen.aliyuncs.com'NAMEPACE = 'youli371966511'APP_NAME = 'note_go'}
}
保存之后如图