参考:kubernetes 部署 Jenkins jenkins kubernetes pipeline_mob64ca14116c53的技术博客_51CTO博客
第七篇:kubernetes部署jenkins-CSDN博客
1、当前kubernetes集群已部署nfs服务
showmount -e
创建jenkins目录
2、添加jenkins的pvc
kubectl create namespace jenkins-k8s
cd /opt/dockerfile/jenkins/
touch jenkins-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:name: jenkins-k8s-pv
spec:capacity:storage: 10GiaccessModes:- ReadWriteManynfs:server: 192.168.1.247path: /opt/nfsdata/jenkins
touch jeckins-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:name: jenkins-k8s-pvcnamespace: jenkins-k8s
spec:resources:requests:storage: 10GiaccessModes:- ReadWriteMany
kubectl get pv -n jenkins-k8s
创建一个sa账号,做rbac授权
kubectl create sa jenkins-k8s-sa -n jenkins-k8s
kubectl create clusterrolebinding jenkins-k8s-sa-cluster -n jenkins-k8s --clusterrole=cluster-admin --serviceaccount=jenkins-k8s:jenkins-k8s-sa
2、部署 jenkins
kubectl apply -f jeckins-deploy.yaml
kind: Deployment
apiVersion: apps/v1
metadata:name: jenkinsnamespace: jenkins-k8s
spec:replicas: 1selector:matchLabels:app: jenkinstemplate:metadata:labels:app: jenkinsspec:serviceAccount: jenkins-k8s-sacontainers:- name: jenkinsimage: jenkins/jenkins:ltsimagePullPolicy: IfNotPresentports:- containerPort: 8080name: webprotocol: TCP- containerPort: 50000name: agentprotocol: TCPresources:limits:cpu: 1000mmemory: 1Girequests:cpu: 500mmemory: 512MilivenessProbe:httpGet:path: /loginport: 8080initialDelaySeconds: 60timeoutSeconds: 5failureThreshold: 12readinessProbe:httpGet:path: /loginport: 8080initialDelaySeconds: 60timeoutSeconds: 5failureThreshold: 12volumeMounts:- name: jenkins-volumesubPath: jenkins-homemountPath: /var/jenkins_homevolumes:- name: jenkins-volumepersistentVolumeClaim:claimName: jenkins-k8s-pvc
kubectl apply -f jeckins-deploy.yaml
kubectl describe pod jenkins-74bb6797d9-qd92c -n jenkins-k8s
kubectl logs pod jenkins-74bb6797d9-qd92c -c jenkins -n jenkins-k8s
没权限
chown -R 1000:1000 /opt/nfsdata/jenkins
kubectl delete -f jeckins-deploy.yaml
重装
kubectl apply -f jeckins-deploy.yaml
kubectl get pod -n jenkins-k8s -owide
3、验证
kubectl get pod -n jenkins-k8s -owide
curl 10.100.27.19:8080
4、kubectl apply -f jenkins-service.yaml
apiVersion: v1
kind: Service
metadata:name: jenkins-servicenamespace: jenkins-k8slabels:app: jenkins
spec:selector:app: jenkinstype: NodePortports:- name: webport: 8080targetPort: webnodePort: 30002- name: agentport: 50000targetPort: agent
kubectl get svc -n jenkins-k8s
cd /opt/nfsdata/jenkins/jenkins-home/secrets
若无法正常配置,可尝试http://192.168.1.12:30002/restart
安装推荐的插件:
创建用户名密码,搭建完成。
http://192.168.1.247:30002/