CI&CD
Git代码仓库
Drone
关联GOGS
Jenkins安装
Jenkins问题
JDK及Maven安装
插件安装
创建示例项目
CI流程
Tekton安装
tekton yaml文件
dashboard yaml文件
trigger yaml文件
Tekton使用(demo)
ArgoCD安装
ArgoCD使用
Tekton结合ArgoCD流水线
git-clone.yaml
docker-build.yaml
git-docker-build-pipline.yaml
helm-change-config.yaml
webhook触发器
本文档使用MrDoc发布
返回首页
-
+
Jenkins安装
2022年8月2日 15:51
admin
##参考资料 https://wiki.eryajf.net/pages/2415.html https://www.jenkins.io/zh/ --- #K8S部署 ####1、下载git包 git clone https://github.com/scriptcamp/kubernetes-jenkins ####2、k8s创建命名空间 kubectl create namespace devops-tools ####3、创建权限文件 vim serviceAccount.yaml ---------------------------------------- --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: jenkins-admin rules: - apiGroups: [""] resources: ["*"] verbs: ["*"] --- apiVersion: v1 kind: ServiceAccount metadata: name: jenkins-admin namespace: devops-tools --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: jenkins-admin roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: jenkins-admin subjects: - kind: ServiceAccount name: jenkins-admin namespace: devops-tools --- kubectl apply -f serviceAccount.yaml --- ####4、创建存储 vim volume.yaml ------------------------------------------------ --- ####5、创建deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: jenkins namespace: devops-tools spec: replicas: 1 selector: matchLabels: app: jenkins-server template: metadata: labels: app: jenkins-server spec: securityContext: fsGroup: 1000 runAsUser: 1000 serviceAccountName: jenkins-admin containers: - name: jenkins image: jenkins/jenkins:lts resources: limits: memory: "2Gi" cpu: "1000m" requests: memory: "500Mi" cpu: "500m" ports: - name: httpport containerPort: 8080 - name: jnlpport containerPort: 50000 livenessProbe: httpGet: path: "/login" port: 8080 initialDelaySeconds: 90 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 5 readinessProbe: httpGet: path: "/login" port: 8080 initialDelaySeconds: 60 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 3 volumeMounts: - name: jenkins-data mountPath: /var/jenkins_home #===================================================== #使用存储卷 volumes: - name: jenkins-data persistentVolumeClaim: claimName: jenkins-pv-claim #===================================================== volumes: - name: jenkins-data emptyDir: {} --- ####6、创建service.yml vim service.yml -------------------------------------------------------- apiVersion: v1 kind: Service metadata: name: jenkins-service namespace: devops-tools annotations: prometheus.io/scrape: 'true' prometheus.io/path: / prometheus.io/port: '8080' spec: selector: app: jenkins-server type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 32000 --- ####7、查看初始密码 kubectl exec -it jenkins-559d8cd85c-cfcgk cat /var/jenkins_home/secrets/initialAdminPassword -n devops-tools --- ##一、下载Jenkins的war包 https://jenkins.io/zh/ ![](/media//202003/2020-03-25131923194432.png) ##启动方法一:(需先安装tomcat) >####1.把war包放到tomcat的webapp目录下 >####2.启动tomcat服务 >####3.访问jenkins http://IP:8080 ##启动方式二: >####1.java启动服务 java -jar jenkins.war >####2.访问jenkins http://IP:8080 --- #Docker方式 ####拉取镜像 docker pull jenkins/jenkins --- ####启动容器 mkdir -p /home/jenkins_home docker run -d -u root -p 8080:8080 -p 50000:50000 -v /home/jenkins_home:/var/jenkins_home --env JAVA_OPTS=-Dhudson.model.DownloadService.noSignatureCheck=true --name jenkins jenkins/jenkins --- ####启动参数说明 |参数|说明| |--|-- |-d|后台运行容器,并返回容器ID |-uroot|使用 root 身份进入容器,推荐加上,避免容器内执行某些命令时报权限错误 |-p 9095:8080|将容器内8080端口映射至宿主机9095端口,这个是访问jenkins的端口 |-p 50000:50000|将容器内50000端口映射至宿主机50000端口 |--name jenkins|设置容器名称为jenkins |-v /home/jenkins_home:/var/jenkins_home :/var/jenkins_home目录为容器jenkins工作目录,我们将硬盘上的一个目录挂载到这个位置,方便后续更新镜像后继续使用原来的工作目录 |-v /etc/localtime:/etc/localtime|让容器使用和服务器同样的时间设置 |jenkins/jenkins|镜像的名称,这里也可以写镜像ID --- ####登陆jenkins ####1、http://<ip>:8080 --- ####2、docker logs jenkins,查看初始登陆密码 --- ![](/media//202208/2022-08-03151052075132.png) --- ####3、选择推荐,进行插件下载 ![](/media//202208/2022-08-03151316375866.png) --- #更换安装源 ####因为网络原因,需要将插件源设置为国内的,这样才可以安装插件。进入宿主机目录 /home/jenkins_home/,编辑文件 hudson.model.UpdateCenter.xml --- cd /home/jenkins_home/ cat hudson.model.UpdateCenter.xml --- ####将 url 内容修改为 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json(清华大学官方镜像) ####镜像列表:选择jenkins对应版本的,lts版本要使用dynamic-stable-xxxxxx。 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/ --- ####重启容器 docker restart jenkins
分享到: