安装nfs服务器
systemctl stop rpcbind.socket
systemctl stop rpcbind
systemctl disable rpcbind.socket
systemctl disable rpcbind
mkdir -p ~/nfs/files
chmod -R 777 ~/nfs/files
echo "/files *(rw,sync,no_subtree_check,fsid=0,no_root_squash)" > ~/nfs/exports.txt
docker run --name nfs -d --rm\
-v ~/nfs/files:/files\
-v ~/nfs/exports.txt:/etc/exports:ro\
--cap-add SYS_ADMIN\
-p 2049:2049 -p 2049:2049/udp \
-p 111:111 -p 111:111/udp \
-p 32765:32765 -p 32765:32765/udp \
-p 32767:32767 -p 32767:32767/udp \
erichough/nfs-server
使用showmount命令查看效果
使用rancher把nfs挂载到k8s上
查看效果
部署jenkins
在rancher上创建一个新的部署
指定workspace路径为nfs
查看效果
核对rancher生成的配置文件
pv
{
"kind": "PersistentVolume",
"apiVersion": "v1",
"metadata": {
"name": "jenkins",
"selfLink": "/api/v1/persistentvolumes/jenkins",
"uid": "218fb160-5f63-11e9-9904-00505627dade",
"resourceVersion": "26862",
"creationTimestamp": "2019-04-15T09:44:58Z",
"labels": {
"cattle.io/creator": "norman"
},
"annotations": {
"field.cattle.io/creatorId": "user-c4qsr",
"pv.kubernetes.io/bound-by-controller": "yes"
},
"finalizers": [
"kubernetes.io/pv-protection"
]
},
"spec": {
"capacity": {
"storage": "100Gi"
},
"nfs": {
"server": "172.16.67.160",
"path": "/files/jenkins"
},
"accessModes": [
"ReadWriteOnce",
"ReadOnlyMany",
"ReadWriteMany"
],
"claimRef": {
"kind": "PersistentVolumeClaim",
"namespace": "default",
"name": "jenkins",
"uid": "b202f7a7-5f63-11e9-9904-00505627dade",
"apiVersion": "v1",
"resourceVersion": "26859"
},
"persistentVolumeReclaimPolicy": "Retain"
},
"status": {
"phase": "Bound"
}
}
pvc
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
field.cattle.io/creatorId: user-c4qsr
pv.kubernetes.io/bind-completed: "yes"
creationTimestamp: 2019-04-15T09:49:00Z
finalizers:
- kubernetes.io/pvc-protection
labels:
cattle.io/creator: norman
name: jenkins
namespace: default
resourceVersion: "26864"
selfLink: /api/v1/namespaces/default/persistentvolumeclaims/jenkins
uid: b202f7a7-5f63-11e9-9904-00505627dade
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
storageClassName: ""
volumeName: jenkins
status:
accessModes:
- ReadWriteOnce
- ReadOnlyMany
- ReadWriteMany
capacity:
storage: 100Gi
phase: Bound
jenkins
apiVersion: apps/v1beta2
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
field.cattle.io/creatorId: user-c4qsr
field.cattle.io/publicEndpoints: '[{"addresses":["172.16.67.150"],"port":33031,"protocol":"TCP","serviceName":"default:jenkins-nodeport","allNodes":true}]'
creationTimestamp: 2019-04-15T09:49:00Z
generation: 2
labels:
cattle.io/creator: norman
workload.user.cattle.io/workloadselector: deployment-default-jenkins
name: jenkins
namespace: default
resourceVersion: "27005"
selfLink: /apis/apps/v1beta2/namespaces/default/deployments/jenkins
uid: b20e4501-5f63-11e9-9904-00505627dade
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
workload.user.cattle.io/workloadselector: deployment-default-jenkins
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
cattle.io/timestamp: 2019-04-15T09:48:59Z
field.cattle.io/ports: '[[{"containerPort":8080,"dnsName":"jenkins-nodeport","kind":"NodePort","name":"8080tcp01","protocol":"TCP","sourcePort":0}]]'
creationTimestamp: null
labels:
workload.user.cattle.io/workloadselector: deployment-default-jenkins
spec:
containers:
- image: jenkins/jenkins:lts-jdk11
imagePullPolicy: Always
name: jenkins
ports:
- containerPort: 8080
name: 8080tcp01
protocol: TCP
resources: {}
securityContext:
allowPrivilegeEscalation: false
capabilities: {}
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: false
stdin: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty: true
volumeMounts:
- mountPath: /var/jenkins_home
name: jenkins
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: jenkins
persistentVolumeClaim:
claimName: jenkins
status:
availableReplicas: 1
conditions:
- lastTransitionTime: 2019-04-15T09:50:21Z
lastUpdateTime: 2019-04-15T09:50:21Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: 2019-04-15T09:49:00Z
lastUpdateTime: 2019-04-15T09:50:21Z
message: ReplicaSet "jenkins-5d7cd689bf" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 2
readyReplicas: 1
replicas: 1
updatedReplicas: 1