helm安装配置jenkins
1、k8s1.28.2、helm3.12.0,集群搭建
查看节点运行情况
kubectl get node -o wide
openebs部署情况
kubectl get sc -n openebs
2、添加Jenkins Helm仓库
helm repo add jenkins https://charts.jenkins.iohelm repo update# 查看版本
helm search repo -l jenkins/jenkins
3、创建命名空间
kubectl create namespace jenkins
看看有哪些 可用的StorageClass
kubectl get storageclass
4、配置jenkins-values.yaml:(顺带JDK17、调度到zk3节点,用openebs-hostpath存储)
controller:numExecutors: 2image:registry: docker.iorepository: jenkins/jenkinstag: lts-jdk17serviceType: NodePortnodePort: 30080persistence:enabled: truestorageClass: openebs-hostpathadditionalVolumes:- name: host-mavenhostPath:path: /opt/maventype: DirectoryadditionalVolumeMounts:- name: host-mavenmountPath: /opt/mavennodeSelector:kubernetes.io/hostname: zk3
执行安装:
#如果之前存在,则先清空
helm uninstall jenkins -n jenkins#安装
helm upgrade --install jenkins jenkins/jenkins \-n jenkins \-f jenkins-values.yaml
安装完成:
5、进入http://ip:30080,配置Manage Jenkins ---->Plugins
gitlab、harbor、maven、docker、Kubernetes、Config File Provider等
拿到初始密码
kubectl -n jenkins exec -it jenkins-0 -- cat /run/secrets/chart-admin-password && echo
6、Manage Jenkins ---->Managed files配置setting私有库nexus连接
#如果没安装nexus私有库,找一个node节点用docker安装即可
docker run -d --name nexus -p 8081:8081 -v /opt/sonatype/sonatype-work:/nexus-data sonatype/nexus3#找到admin.password拿到密码登录
http://ip:8081#新增一个配置
Add a new Config#选择
Maven settings.xml#改掉下面的id为:
my-settings #点击下一步#在Content中配置加入以下内容<servers><server><id>nexus</id><username>admin</username><password>ok5201314</password> <!-- 换成你自己的密码 --></server></servers><mirrors><!-- 阿里云仓库,个人配置 --><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/repositories/central/</url></mirror></mirrors><profiles><profile><id>use-nexus</id><repositories><repository><id>nexus</id><url>http://192.168.3.60:8081/repository/maven-snapshots/</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></repository></repositories></profile></profiles><activeProfiles><activeProfile>use-nexus</activeProfile></activeProfiles>
7、在微服务的pipeline script中配置如下:
gitlab-pat配置gitlab的账号/密码凭证, 通过mvn clean deploy -DskipTests --settings $MAVEN_SETTINGS推送到微服务中配置的私有库
pipeline {agent anytools {maven 'Maven-3.8.6'}environment {GIT_USER_NAME = 'root' #gitlab账号GIT_USER_EMAIL = 'admin@example.com' #gitlab邮箱}stages {stage('Checkout') {steps {checkout([$class: 'GitSCM',branches: [[name: '*/main']],extensions: [submodule(parentCredentials: true, recursiveSubmodules: true),[$class: 'UserIdentity', email: "${env.GIT_USER_EMAIL}", name: "${env.GIT_USER_NAME}"]],userRemoteConfigs: [[credentialsId: 'gitlab-pat',url: 'http://192.168.3.60:9980/spring_cloud_java/spring-cloud-parent.git']]])}}stage('Deploy to Nexus') {steps {configFileProvider([configFile(fileId: 'my-settings', variable: 'MAVEN_SETTINGS')]) {sh 'mvn clean deploy -DskipTests --settings $MAVEN_SETTINGS'}}}}post {failure {echo "构建失败!请检查日志。"}success {echo "构建并部署成功!"}}
}
8、spring-cloud-parent、common微服务中配置
<project>
<distributionManagement><snapshotRepository><id>nexus</id><url>http://192.168.3.60:8081/repository/maven-snapshots/</url></snapshotRepository></distributionManagement>
</project>
9、在user-center配置
<project>
<dependencyManagement><dependencies><!-- 引入 common 的 dependencyManagement 配置 --><dependency><groupId>org.algorithm</groupId><artifactId>common</artifactId><version>1.0-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies>
<dependency><groupId>org.algorithm</groupId><artifactId>common</artifactId><version>1.0-SNAPSHOT</version><scope>compile</scope></dependency></dependencies><repositories><repository><id>nexus</id><url>http://192.168.3.60:8081/repository/maven-snapshots/</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>true</enabled></releases></repository></repositories></project>
10、首先构建spring-cloud-parent、再构建common
如果有版本修改common,需要先构建common,再构建user-center