简体   繁体   English

Jenkins容器在Kubernetes集群上的持久性-PersistentVolumeClaim(VMware / Vsphere)

[英]Jenkins container persistence on Kubernetes cluster - PersistentVolumeClaim (VMware/Vsphere)

Trying to persist my jenkins jobs on to vsphere storage when I delete the deployments/services. 删除部署/服务时尝试将我的jenkins作业持久保存到vSphere存储中。

I've tried using the standard approach: used StorageClass, then made a PersistentVolumeClaim which is referenced in the .ayml file that will create the deployments. 我尝试使用标准方法:使用StorageClass,然后制作一个PersistentVolumeClaim,该文件在将创建部署的.ayml文件中引用。

storage-class.yml: storage-class.yml:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: mystorage
provisioner: kubernetes.io/vsphere-volume
parameters:
  diskformat: zeroedthick

persistent-volume-claim.yml: 持续体积声明.yml:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc0003
spec:
  storageClassName: mystorage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 15Gi

jenkins.yml: jenkins.yml:

---
apiVersion: v1
kind: Service
metadata:
  name: jenkins-auto-ci
  labels:
    app: jenkins-auto-ci
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: jenkins-auto-ci
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins-auto-ci
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: jenkins-auto-ci
    spec:
      containers:
      - name: jenkins-auto-ci
        image: jenkins
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
        ports:
        - name: http-port
          containerPort: 80
        - name: jnlp-port
          containerPort: 50000
        volumeMounts:
        - name: jenkins-home
          mountPath: "/var"
      volumes:
        - name: jenkins-home
          persistentVolumeClaim:
            claimName: pvc0003

I expect the jenkins jobs to persist when I delete and recreate the deployments. 我希望在删除并重新创建部署时,jenkins作业能够继续存在。

You should create VMDK which is Virtual Machine Disk. 您应该创建VMDK ,它是虚拟机磁盘。

You can do that using govc which is vSphere CLI. 您可以使用作为 vSphere CLI的govc进行此操作。

govc datastore.disk.create -ds datastore1 -size 2G volumes/myDisk.vmdk

Or using ESXi CLI by ssh into the host as root and executing: 或通过ssh使用ESXi CLIroot身份进入主机并执行以下命令:

vmkfstools -c 2G /vmfs/volumes/datastore1/volumes/myDisk.vmdk

Once this is done you should create your PV let's call it vsphere_pv.yaml which might look like the following: 完成此操作后,应创建PV,将其vsphere_pv.yaml ,如下所示:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0001
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  vsphereVolume:
    volumePath: "[datastore1] volumes/myDisk"
    fsType: ext4

The datastore1 in this example was created in root folder of vCenter, if you have it in a different location you need to change the volumePath . 本示例中的datastore1是在vCenter的根文件夹中创建的,如果您将其放置在其他位置,则需要更改volumePath If it's located in DatastoreCluster then set volumePath to "[DatastoreCluster/datastore1] volumes/myDisk" . 如果位于DatastoreCluster则将volumePath设置为"[DatastoreCluster/datastore1] volumes/myDisk"

Apply the yaml to the Kubernetes by kubectl apply -f vsphere_pv.yaml 通过kubectl apply -f vsphere_pv.yaml yaml应用于kubectl apply -f vsphere_pv.yaml

You can check if it was created by describing it kubectl describe pv pv0001 您可以通过描述它来检查它是否已创建kubectl describe pv pv0001

Now you need PVC let's call it vsphere_pvc.yaml to consume PV. 现在您需要PVC,我们将其vsphere_pvc.yaml以消耗PV。

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc0001
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

Apply the yaml to the Kubernetes by kubectl apply -f vsphere_pvc.yaml 通过kubectl apply -f vsphere_pvc.yaml

You can check if it was created by describing it kubectl describe pvc pv0001 您可以通过描述它来检查它是否已创建kubectl describe pvc pv0001

Once this is done your yaml might be looking like the following: 完成此操作后,您的yaml可能如下所示:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins-auto-ci
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: jenkins-auto-ci
    spec:
      containers:
      - name: jenkins-auto-ci
        image: jenkins
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
        ports:
        - name: http-port
          containerPort: 80
        - name: jnlp-port
          containerPort: 50000
        volumeMounts:
        - name: jenkins-home
          mountPath: "/var"
      volumes:
        - name: jenkins-home
          persistentVolumeClaim:
            claimName: pvc0001

All this is nicely explained on Vmware GitHub vsphere-storage-for-kubernetes . 所有这些在Vmware GitHub vsphere-storage-for-kubernetes都有很好的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 作为容器运行的 Jenkins 上永久节点的持久性 kubernetes - Persistence of permanent node on Jenkins running as container kubernetes Jenkins在Kubernetes集群上的安装 - Jenkins Installation On Kubernetes Cluster 在Kubernetes集群中部署Jenkins - Deploy Jenkins in Kubernetes cluster jenkins 从站的 PersistentVolumeClaim 工作区 - PersistentVolumeClaim workspace for jenkins slave Kubernetes 尝试将 jenkins 添加到集群 - Kubernetes Try to add jenkins to a cluster 如何仅针对 Jenkins 管道后期条件指定要在 Kubernetes 集群上执行的容器/代理 - How to specify a container / agent to execute on Kubernetes cluster for Jenkins pipeline post condition only 让 Jenkins Docker 容器在 Kubernetes 集群本身内部处理 CI/CD 是不好的做法吗? - Is it bad practice to have a Jenkins Docker container to handle CI/CD inside the Kubernetes cluster itself? 独立的Jenkins与Kubernetes Cluster建立集成 - Standalone Jenkins build integration with Kubernetes Cluster Jenkins 构建 Docker 守护程序不在 kubernetes 集群上运行 - Jenkins build Docker daemon not running on kubernetes cluster 使用Jenkins在本地kubernetes集群中实现CD? - Implementation of CD with Jenkins for on premise kubernetes cluster?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM