k8s分布式存储,使用rancher将jenkins workspace部署在nfs上

安装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
复制代码

转载于:https://juejin.im/post/5cb46f44e51d456e303db86b

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值