接上一篇,搭建好glusterfs集群后,我们接下来创建单独的卷给jenkins使用,脚本已写好,直接运行即可:
#!/bin/sh if [ $# -lt 2 ]; then echo "please input at least 2 param" exit 0 fi glusterfs_volume_name=$1 glusterfs_volume_path=$2 #dbSize=$3 gluster volume create $glusterfs_volume_name replica 2 gluster1:/data//brick1/$glusterfs_volume_path gluster2:/data//brick1/$glusterfs_volume_path force gluster volume list gluster volume start $glusterfs_volume_name
sh cg.sh k8s-volume-jenkins-master jenkins-master
编写endpoints.yaml文件,内容如下:
--- apiVersion: v1 kind: Endpoints metadata: name: glusterfs-cluster namespace: ci subsets: - addresses: [{"ip": "23.234.215.72"}, {"ip": "108.166.210.228"}] ports: [{"port": 24007}] 编写service.yaml文件,内容如下: --- apiVersion: v1 kind: Service metadata: name: glusterfs-cluster namespace: ci spec: ports: - port: 24007 targetPort: 24007 protocol: TCP
创建namespace.yaml文件:
--- apiVersion: v1 kind: Namespace metadata: name: ci
创建jenkins-master-pv.yaml
apiVersion: v1 kind: PersistentVolume metadata: name: pv-jenkins-master namespace: ci spec: capacity: storage: 1Gi accessModes: - ReadWriteMany glusterfs: endpoints: "glusterfs-cluster" path: "k8s-volume-jenkins-master" readOnly: false
创建pvc:jenkins-master-pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-jenkins-master namespace: ci spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi
创建jenkins-deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: namespace: ci name: jenkins spec: replicas: 1 selector: matchLabels: app: jenkins template: metadata: labels: app: jenkins spec: securityContext: fsGroup: 1000 runAsUser: 0 containers: - name: jenkins image: jenkins ports: - containerPort: 8000 volumeMounts: - name: home mountPath: "/var/jenkins_home" volumes: - name: home persistentVolumeClaim: claimName: pvc-jenkins-master
创建jenkins_service.yaml:
--- apiVersion: v1 kind: Service metadata: namespace: ci name: jenkins labels: name: jenkins spec: ports: - port: 8080 targetPort: 8080 name: jenkins protocol: TCP selector: app: jenkins type: NodePort
运行:
kubectl create -f namespace.yaml kubectl create -f jenkins-master-pv.yaml kubectl create -f jenkins-master-pvc.yaml kubectl create -f jenkins-deployment.yaml kubectl create -f jenkins_service.yaml
安装过程中遇到的问题:
Jenkins启动,backoffrestarfailling
查看日志,报错如下:
kubectl logs jenkins-7c97f9d6d9-q6fk9 -n ci touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?
加了一段配置解决:
spec: securityContext: fsGroup: 1000 runAsUser: 0
因为jenkins 运行的用户 id是1000,加上权限。
进入容器:
kubectl exec -it -n ci jenkins-bff9cccdd-45jzx – bash
more /var/jenkins_home/secrets/initialAdminPassword #查看初始密码
用Node ip加端口访问,发现正常。