创建本地存储

由于是测试集群,我们这里直接使用本地volume存储即可;

由于这里jenkins server里运行用户为jenkins,且jenkins的uid为1000,我们需要在node1上提前将/opt/jenkins_agent/和/opt/jenkins_maven/权限授权给jenkins

1
2
chown 1000.1000 -R  /opt/jenkins_agent -R
chown 1000.1000 -R  /opt/jenkins_maven/ -R

本地存储:agent-pv-pvc.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-agent-pv
spec:
  storageClassName: local # Local PV
  capacity:
    storage: 30Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  local:
    path: /opt/jenkins_agent
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - node01
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-agent-pvc
  namespace: kube-ops
spec:
  storageClassName: local
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 30Gi

本地存储:maven-pv-pvc.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-maven-pv
spec:
  storageClassName: local # Local PV
  capacity:
    storage: 30Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  local:
    path: /opt/jenkins_maven
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - node01
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: jenkins-maven-pvc
  namespace: kube-ops
spec:
  storageClassName: local
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 30Gi

创建PV和PVC资源

1
2
3
4
5
6
7
# kubectl apply -f  agent-pv-pvc.yaml
persistentvolume/jenkins-agent-pv created
persistentvolumeclaim/jenkins-agent-pvc created

# kubectl apply -f  maven-pv-pvc.yaml
persistentvolume/jenkins-maven-pv created
persistentvolumeclaim/jenkins-maven-pvc created