kubernetes上部署jenkins
【摘要】 1.简介提前部署storageclass,并且名称为nfs-csi的StorageClass资源Kubernetes集群上部署有Ingress Nginx Controller 2.namespace$ kubectl create namespace jenkins 3.pvc---apiVersion: v1kind: PersistentVolumeClaimmetadata: n...
1.简介
- 提前部署storageclass,并且名称为nfs-csi的StorageClass资源
- Kubernetes集群上部署有Ingress Nginx Controller
2.namespace
$ kubectl create namespace jenkins
3.pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pvc
namespace: jenkins
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: nfs-csi
4.RBAC
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins-master
namespace: jenkins
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: jenkins-master
rules:
- apiGroups: ["extensions", "apps"]
resources: ["deployments"]
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
- apiGroups: [""]
resources: ["services"]
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get","list","watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: jenkins-master
roleRef:
kind: ClusterRole
name: jenkins-master
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: jenkins-master
namespace: jenkins
5.deploy
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
serviceAccountName: jenkins-master
volumes:
- name: jenkins-store
persistentVolumeClaim:
claimName: jenkins-pvc
initContainers:
- name: fix-permissions
image: alpine
command: ["sh", "-c", "chown -R 1000:1000 /var/jenkins_home/"]
securityContext:
privileged: true
volumeMounts:
- name: jenkins-store
mountPath: /var/jenkins_home/
containers:
- name: jenkins
#image: jenkins/jenkins:jdk17
image: jenkins/jenkins:lts-jdk17
#image: jenkins/jenkins:lts
volumeMounts:
- name: jenkins-store
mountPath: /var/jenkins_home/
imagePullPolicy: IfNotPresent
env:
- name: JAVA_OPTS
value: -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia/Shanghai -Djenkins.install.runSetupWizard=true
ports:
- containerPort: 8080
name: web
protocol: TCP
- containerPort: 50000
name: agent
protocol: TCP
5.deploy2
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
securityContext:
fsGroup: 1000
runAsUser: 1000
serviceAccountName: jenkins-master
containers:
- name: jenkins
image: jenkins/jenkins:lts
#resources:
# limits:
# memory: "2Gi"
# cpu: "1000m"
# requests:
# memory: "500Mi"
# cpu: "500m"
ports:
- name: web
containerPort: 8080
- name: agent
containerPort: 50000
#livenessProbe:
# httpGet:
# path: "/login"
# port: 8080
# initialDelaySeconds: 90
# periodSeconds: 10
# timeoutSeconds: 5
# failureThreshold: 5
#readinessProbe:
# httpGet:
# path: "/login"
# port: 8080
# initialDelaySeconds: 60
# periodSeconds: 10
# timeoutSeconds: 5
# failureThreshold: 3
volumeMounts:
- name: jenkins-store
mountPath: /var/jenkins_home/
volumes:
- name: jenkins-store
persistentVolumeClaim:
claimName: jenkins-pvc
6.service
---
apiVersion: v1
kind: Service
metadata:
name: jenkins
namespace: jenkins
labels:
app: jenkins
spec:
selector:
app: jenkins
type: NodePort
ports:
- name: web
port: 8080
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: jenkins-jnlp
namespace: jenkins
labels:
app: jenkins
spec:
selector:
app: jenkins
ports:
- name: agent
port: 50000
targetPort: 50000
7.maven cache
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-maven-cache
namespace: jenkins
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: nfs-csi
8.ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: jenkins
namespace: jenkins
spec:
ingressClassName: nginx
rules:
- host: cicd.leepongmin.com
http:
paths:
- backend:
service:
name: jenkins
port:
number: 8080
path: /
pathType: Prefix
- host: jenkins.leepongmin.com
http:
paths:
- backend:
service:
name: jenkins
port:
number: 8080
path: /
pathType: Prefix
【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)