参考: 第七篇:kubernetes部署jenkins-CSDN博客
1、当前kubernetes集群已部署nfs服务
showmount -e
创建jenkins目录
2、添加jenkins的pvc
cd /opt/dockerfile/jenkins/
touch jenkins-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-jenkins
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: "pv-jenkins"
nfs:
path: /opt/nfsdata/jenkins
server: 192.168.1.247
kubectl apply -f jenkins-pv.yaml
2、部署 jenkins
kubectl create namespace devops
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: devops
name: service-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["services"]
verbs: ["get", "watch", "list"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get","list","watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: devops
name: jenkins-sa
labels:
account: jenkins
---
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: jenkins-crd
roleRef:
kind: ClusterRole
name: service-reader
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: jenkins-sa
namespace: devops
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pvc
namespace: devops
spec:
accessModes:
- ReadWriteMany
storageClassName: "pv-jenkins"
resources:
requests:
storage: 3Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: devops
labels:
app: jenkins
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
version: v1
template:
metadata:
labels:
app: jenkins
version: v1
spec:
serviceAccountName: jenkins-sa
containers:
- name: jenkins
image: jenkins/jenkins:2.387
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: web
protocol: TCP
- containerPort: 50000
name: agent
protocol: TCP
resources:
limits:
cpu: 2000m
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /login
port: 8080
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
readinessProbe:
httpGet:
path: /login
port: 8080
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
volumeMounts:
- name: jenkins-volume
mountPath: /var/jenkins_home
subPath: jenkins
volumes:
- name: jenkins-volume
persistentVolumeClaim:
claimName: jenkins-pvc
---
apiVersion: v1
kind: Service
metadata:
name: jenkins
namespace: devops
labels:
app: jenkins
service: jenkins
spec:
selector:
app: jenkins
type: ClusterIP
ports:
- name: web
port: 8080
targetPort: web
- name: agent
port: 50000
targetPort: agent
kubectl apply -f jenkins.yaml