第十二课 Kubernetes生产级实践-jenkins弹性pod执行机
一、k8s中安装jenkins
1.1配置持久化储存NFS
- 安装配置服务器端nfs
yum install -y nfs-common nfs-utils rpcbind
mkdir /nfsdata /nfsdata1 /nfs/data/jenkins
chmod 777 /nfsdata /nfsdata1 /nfs/data/jenkins
vim /etc/exports
/nfsdata *(rw,no_root_squash,no_all_squash,sync)
/nfs/data/jenkins *(rw,no_root_squash,no_all_squash,sync)
systemctl restart rpcbind
systemctl restart nfs
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
systemctl status rpcbind
systemctl status nfs
- 安装配置客户端
yum install -y nfs-utils rpcbind
mkdir /ci-jenkins
showmount -e 192.168.31.210
mount -t nfs 192.168.31.210:/nfsdata /ci-jenkins
cd /ci-jenkins/
ls
vim index.html
cd -
umount /ci-jenkins
rm -rf /ci-jenkins
1.2指定持久化储存
- jenkins_storage.yaml
- 创建jenkins-ci的命名空间
- kubectl create ns kube-ops
- kubectl apply -f jenkins_storage.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: opspv
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Delete
nfs:
server: 192.168.31.210
path: /nfs/data/jenkins
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: opspvc
namespace: kube-ops
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
1.3 创建 ServiceAccount & ClusterRoleBinding
- 将 cluster-admin 绑定到 ServiceAccount 来保证 Jenkins 拥有足够的权限。
- kubectl create -f jenkins-rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins2
namespace: kube-ops
---
kind: ClusterRole
apiVersion