[英]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 CLI以
root
身份进入主机并执行以下命令:
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.