1.創建namespace
apiVersion: v1
kind: Namespace
metadata:
name: jenkins
2.創建deployoment
apiVersion: Apps/v1
kind: Deployment
metadata:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: jenkins/jenkins:lts
ports:
- name: http-port
containerPort: 8080
- name: jnlp-port
containerPort: 50000
volumeMounts:
- name: ops-jenkins-data
mountPath: /var/jenkins_home
initContainers: ###因jenkins家目錄權限需要對掛載的pvc進行權限修改
- args:
- -c
- chmod 755 /var/jenkins_home && chown 1000:1000 /var/jenkins_home
command:
- /bin/sh
image: centos
imagePullPolicy: IfNotPresent
name: chauth
securityContext:
privileged: true ### 建議開啟特權模式
volumeMounts:
- mountPath: /var/jenkins_home ### initc也要對此數據卷進行掛載
name: ops-jenkins-data
volumes:
- name: ops-jenkins-data
persistentVolumeClaim:
claimName: ops-jenkins-data
3.創建針對jenkins相關的service,事例中只針對集群內部開放訪問,如需要可以開啟Nodeport、loadbalancer類型。
apiVersion: v1
kind: Service
metadata:
name: jenkins
spec:
type: ClusterIP
ports:
- port: 8080
targetPort: 8080
selector:
app: jenkins
---
apiVersion: v1
kind: Service
metadata:
name: jenkins-jnlp
spec:
type: ClusterIP
ports:
- port: 50000
targetPort: 50000
selector:
app: jenkins