K8s集群部署最新Jenkins 2.387.1

news/2024/11/13 4:16:05/

K8s集群部署最新Jenkins 2.387.1

      • 概述
      • 环境准备
        • 设置存储目录并启动NFS服务
        • 安装 NFS 服务端
      • 动态创建 NFS存储(动态存储)
      • 部署jenkins服务

概述

Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件项目可以进行持续集成。在Devops时代Jenkins有着不可缺失地位,也体现了Jenkins的亮点,废话不多说,我们进入在k8s环境下安装最新的Jenkins。

环境准备

一般k8s的数据都会存放于远程存储服务器上来保证安全,采用的方式也有很多,如nfs,ceph等等多种,这里我们介绍nfs存储。nfs存储配置简单,但存是储量特别大,传输特别频繁的情况下难免会出现传输延迟,难以保证高并发时的数据完整性和高性能等问题,但是很多公司的基本要求还是可以满足的。

这里我们需要先创建一台虚拟机或者服务器作为NFS服务器,这里笔者已经提前创建好了网段和k8s环境一样,然后往k8s所有master节点和worker节点host加入nfs主机映射,在hosts文件加入如下内容:

#nfs主机的ip 后面挂在会用到name
10.211.55.6 storage

设置存储目录并启动NFS服务

我们先创建共享目录,比如这里需要创建/data/k8s 目录,需要提前创建,然后往/etc/exports文件加入对应的nfs共享配置,具体操作如下:

#创建nfs共享目录
mkdir -p /data/k8s
#修改权限
chmod 777 -R 777 /data
#往exports文件写入配置,然后保存
vi /etc/exports
/data/k8s   10.211.55.0/24(rw,no_root_squash,sync)
#配置生效
exportfs -r
#查看生效
exportfs#安装nfs服务
yum -y install nfs-utils
#启动rpcbind、nfs服务
systemctl restart rpcbind && systemctl enable rpcbind
systemctl restart nfs && systemctl enable nf

安装 NFS 服务端

我们在worker节点安装nfs服务,不需要启动,这里只是需要测试挂载,如果已经安装请忽略即可。

#所有worker节点安装客户端,不需要启动
yum -y install nfs-utils
# worker节点测试挂载storage=nfs服务地址
mount -t nfs storage:/data/k8s /mnt
# 卸载
umount /mnt

动态创建 NFS存储(动态存储)

mkdir my-nfs-client-provisioner && cd my-nfs-client-provisioner
#nfs rbac
cat > rbac.yaml << EOF
apiVersion: v1
kind: ServiceAccount
metadata:name: nfs-client-provisioner# replace with namespace where provisioner is deployednamespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:name: nfs-client-provisioner-runner
rules:- apiGroups: [""]resources: ["persistentvolumes"]verbs: ["get", "list", "watch", "create", "delete"]- apiGroups: [""]resources: ["persistentvolumeclaims"]verbs: ["get", "list", "watch", "update"]- apiGroups: ["storage.k8s.io"]resources: ["storageclasses"]verbs: ["get", "list", "watch"]- apiGroups: [""]resources: ["events"]verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:name: run-nfs-client-provisioner
subjects:- kind: ServiceAccountname: nfs-client-provisioner# replace with namespace where provisioner is deployednamespace: default
roleRef:kind: ClusterRolename: nfs-client-provisioner-runnerapiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:name: leader-locking-nfs-client-provisioner# replace with namespace where provisioner is deployednamespace: default
rules:- apiGroups: [""]resources: ["endpoints"]verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:name: leader-locking-nfs-client-provisioner# replace with namespace where provisioner is deployednamespace: default
subjects:- kind: ServiceAccountname: nfs-client-provisioner# replace with namespace where provisioner is deployednamespace: default
roleRef:kind: Rolename: leader-locking-nfs-client-provisionerapiGroup: rbac.authorization.k8s.io
EOF# nfs deployment
cat > deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:name: nfs-client-provisionerlabels:app: nfs-client-provisioner# replace with namespace where provisioner is deployednamespace: default
spec:replicas: 1strategy:type: Recreateselector:matchLabels:app: nfs-client-provisionertemplate:metadata:labels:app: nfs-client-provisionerspec:serviceAccountName: nfs-client-provisionercontainers:- name: nfs-client-provisionerimage: dyrnq/nfs-subdir-external-provisioner:v4.0.2volumeMounts:- name: nfs-client-rootmountPath: /persistentvolumesenv:- name: PROVISIONER_NAMEvalue: fuseim.pri/ifs- name: NFS_SERVERvalue: storage  # 注意此处修改- name: NFS_PATHvalue: /data/k8s   # 注意此处修改volumes:- name: nfs-client-rootnfs:server: storage   # 注意此处修改path: /data/k8s    # 注意此处修改
EOF# nfs class
cat > class.yaml << EOF
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:name: managed-nfs-storage
provisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:archiveOnDelete: "false"
EOF

部署jenkins服务

mkdir jenkins & cd jenkins#jenkins rbac
cat > Jenkins-rbac.yaml << EOF
apiVersion: v1
kind: Namespace
metadata:name: jenkins
---
apiVersion: v1
kind: ServiceAccount
metadata:name: jenkinsnamespace: jenkins
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:annotations:rbac.authorization.kubernetes.io/autoupdate: "true"labels:kubernetes.io/bootstrapping: rbac-defaultsname: jenkins
rules:
- apiGroups:- '*'resources:- statefulsets- services- replicationcontrollers- replicasets- podtemplates- podsecuritypolicies- pods- pods/log- pods/exec- podpreset- poddisruptionbudget- persistentvolumes- persistentvolumeclaims- jobs- endpoints- deployments- deployments/scale- daemonsets- cronjobs- configmaps- namespaces- events- secretsverbs:- create- get- watch- delete- list- patch- update
- apiGroups:- ""resources:- nodesverbs:- get- list- watch- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:annotations:rbac.authorization.kubernetes.io/autoupdate: "true"labels:kubernetes.io/bootstrapping: rbac-defaultsname: jenkins
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: jenkins
subjects:
- apiGroup: rbac.authorization.k8s.iokind: Groupname: system:serviceaccounts:jenkins
EOF#jenkins deployment
cat > Jenkins-Deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:name: jenkinsnamespace: jenkinslabels:app: jenkins
spec:replicas: 1selector:matchLabels:app: jenkinstemplate:metadata:labels:app: jenkinsspec:containers:- name: jenkinsimage: jenkins/jenkins:lts-jdk11ports:- containerPort: 8080name: webprotocol: TCP- containerPort: 50000name: agentprotocol: TCP#resources:#limits:#memory: 4Gi#cpu: "2000m"#requests:#memory: 4Gi#cpu: "2000m"env:- name: LIMITS_MEMORYvalueFrom:resourceFieldRef:resource: limits.memorydivisor: 1Mi- name: JAVA_OPTSvalue: -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=truevolumeMounts:- name: jenkins-homemountPath: /var/jenkins_homevolumes:- name: jenkins-homepersistentVolumeClaim:claimName: jenkins-home
---
apiVersion: v1
kind:  PersistentVolumeClaim
metadata:name: jenkins-homenamespace: jenkins
spec:storageClassName: "jenkins-nfs-sc"accessModes: [ReadWriteOnce]resources:requests:storage: 20Gi
EOF#jenkins service
cat > Jenkins-Service.yaml << EOF
apiVersion: v1
kind: Service
metadata:name: jenkinsnamespace: jenkinslabels:app: jenkins
spec:selector:app: jenkinsports:- name: webport: 8080targetPort: web- name: agentport: 50000targetPort: agent
EOF#jenkins nfs
cat > jenkins-nfs-sc.yml << EOF
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:name: jenkins-nfs-sc
provisioner: fuseim.pri/ifs 
parameters:archiveOnDelete: "false"
EOF#先部署jenkins nfs
kubectl apply -f jenkins-nfs-sc.yml

执行部署

kubectl apply -f Jenkins-rbac.yaml -f Jenkins-Deployment.yaml -f Jenkins-Service.yaml

查看jenkins初始化信息

kubectl get pods -n jenkins -l app=jenkinskubectl logs -f jenkins-xxxx-xxxx -n jenkins #初始化密钥就在日志里面

通过NodePort暴露端口
注意,也可以通过ingress通过域名方式暴露(推荐)

在这里插入图片描述

# kubectl edit svc jenkins -n jenkins# kubectl get svc -n jenkins
NAME      TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)                          AGE
jenkins   NodePort   10.100.241.123   <none>        8080:32767/TCP,50000:30750/TCP   9m38s

访问:http://10.211.55.3:30002/


http://www.ppmy.cn/news/786118.html

相关文章

旧电脑变废为宝成为nas

老台式机1台 可用任意电脑一台&#xff0c;用来调试nas U盘1个&#xff0c;64M以上 黑群晖安装包 显示器 下载黑群晖安装工具包&#xff1a;http://pan.baidu.com/s/1eRSAwAQ 使用ChipEasy检查并记录U盘的VID PID对应文件目录为&#xff1a;\黑群晖\相关软件\1)ChipEasy芯片无…

360元(含硬盘)!小白二手旧电脑组建超低价NAS记录

起初是自己买树莓派跟朋友一起接触了nextcloud、owncloud等一些私有云平台。这些平台与我个人而言无非就是为了起到类似百度网盘的作用&#xff0c;但相对于百度网盘&#xff0c;云平台在功能&#xff0c;以及传输速度&#xff08;取决于自家宽带&#xff09;&#xff0c;实用性…

硬盘数据传到计算机,如何把旧电脑硬盘上的数据复制传输到新电脑上

如何把旧电脑硬盘上的数据复制传输到新电脑上 电脑旧了就需要升级&#xff0c;如果电脑零件过于残旧而不合适安装到新电脑上使用的话&#xff0c;我们就应该选择放弃&#xff0c;假如旧电脑还有零配件适合新电脑使用&#xff0c;我们就不应该浪费&#xff0c;必须将其安装在新电…

旧电脑当远程服务器,旧电脑平板别丢了!将你身边的屏幕都利用起来

感谢IT之家网友 ARM控股的投稿 或许大家看到这个标题会联想到市面上的一些远程控制软件&#xff0c;诸如&#xff1a;TeamViewer、AnyDesk等。这一次笔者想推荐的并不是一款远程桌面软件&#xff0c;而是一款远程显示软件&#xff0c;甚至可以理解成一款简易的KVM系统。 虽然市…

计算机能使用硬盘吗,旧电脑的硬盘能直接插在新电脑上用吗?

原标题&#xff1a;旧电脑的硬盘能直接插在新电脑上用吗&#xff1f; 如果接口一致&#xff0c;旧电脑的硬盘可以直接在新电脑上使用。 目前家用电脑使用的硬盘均为SATA接口的硬盘&#xff0c;使用SATA口的硬盘又叫串口硬盘&#xff0c;是PC机硬盘的趋势&#xff0c;而SATA接口…

DIY旧电脑-解决旧电脑硬盘无法显示

文章目录 前言从旧电脑上拆下来一块就硬盘,买硬盘盒组装很easy,但是插入电脑却发现无法显示. 一、现象二、原因与解决1. 使用磁盘管理进行回收2.命令行回收EFI系统分区3.磁盘分区 总结 前言 从旧电脑上拆下来一块就硬盘,买硬盘盒组装很easy,但是插入电脑却发现无法显示. 一、…

Unity桌面弹球小游戏Finger Soccer Game Kit 1.1

按住鼠标左键发射打球 还可以开启双人模式来玩 地址&#xff1a;https://download.csdn.net/download/Highning0007/88020441

6-开发模型(5个)

目录 1.瀑布模型&#xff08;Waterfall Model&#xff09; 2.螺旋模型&#xff08;Spiral Model&#xff09; 3.增量模型&#xff08;Incremental Model&#xff09; 4.迭代模型&#xff08;Iterative Model&#xff09; PS&#xff1a;增量模型和迭代模型的区别 5.敏捷模…