- 创建namespace
apiVersion: v1
kind: Namespace
metadata:name: jenkins
- 创建pv以及pvc
kind: PersistentVolume
apiVersion: v1
metadata:name: jenkins-pv-volumenamespace: jenkinslabels:type: localapp: jenkins
spec:capacity:storage: 5GiaccessModes:- ReadWriteManyhostPath:path: "/home/ellis/k8s/Jenkins/jenkinsdata/"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:name: jenkins-pv-claimnamespace: jenkinslabels:app: jenkins
spec:storageClassName: ""accessModes:- ReadWriteManyresources:requests:storage: 5Gi
- 创建deployment以及service
apiVersion: apps/v1
kind: Deployment
metadata:name: jenkinsnamespace: jenkins
spec:replicas: 1selector:matchLabels:app: jenkinstemplate:metadata:labels:app: jenkinsspec:containers:- name: jenkinsimage: jenkins/jenkins:ltsports:- name: http-portcontainerPort: 8080- name: jnlp-portcontainerPort: 50000volumeMounts:- name: jenkins-volmountPath: /var/jenkins_volresources:limits:cpu: 500mmemory: 2Girequests:cpu: 500mmemory: 2Givolumes:- name: jenkins-volpersistentVolumeClaim:claimName: jenkins-pv-claim
---
apiVersion: v1
kind: Service
metadata:name: jenkinsnamespace: jenkins
spec:type: NodePortports:- port: 8080targetPort: 8080nodePort: 30000selector:app: jenkins---apiVersion: v1
kind: Service
metadata:name: jenkins-jnlpnamespace: jenkins
spec:type: ClusterIPports:- port: 50000targetPort: 50000selector:app: jenkins
- 查看admin password
拉到最下面查找password
sudo kubectl logs pod/jenkins-d6fcdfdd6-hqqvd -n jenkins
- 访问http://ip:30000