k8s 中部署Jenkins

  1. 创建namespace
apiVersion: v1
kind: Namespace
metadata:
  name: jenkins
  1. 创建pv以及pvc
kind: PersistentVolume
apiVersion: v1
metadata:
  name: jenkins-pv-volume
  namespace: jenkins
  labels:
    type: local
    app: jenkins
spec:
  #storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/home/ellis/k8s/Jenkins/jenkinsdata/vol"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-pv-claim
  namespace: jenkins
  labels:
    app: jenkins
spec:
  storageClassName: ""
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: jenkinshome-pv-volume
  namespace: jenkins
  labels:
    type: local
    app: jenkins
spec:
  #storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/home/ellis/k8s/Jenkins/jenkinsdata/home"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkinshome-pv-claim
  namespace: jenkins
  labels:
    app: jenkins
spec:
  storageClassName: ""
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi

  1. 创建deployment以及service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: 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
        env:
        - name: TZ
          value: "Asia/Shanghai"
        volumeMounts:
          - name: jenkins-vol
            mountPath: /var/jenkins_vol
          - name: jenkins-home
            mountPath: /var/jenkins_home
        resources:
          limits:
            cpu: 500m
            memory: 2Gi
          requests:
            cpu: 500m
            memory: 2Gi
      volumes:
        - name: jenkins-vol
          persistentVolumeClaim:
            claimName: jenkins-pv-claim
        - name: jenkins-home
          persistentVolumeClaim:
            claimName: jenkinshome-pv-claim
---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: jenkins
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30000
  selector:
    app: jenkins

---

apiVersion: v1
kind: Service
metadata:
  name: jenkins-jnlp
  namespace: jenkins
spec:
  type: ClusterIP
  ports:
    - port: 50000
      targetPort: 50000
  selector:
    app: jenkins





  1. 查看admin password
    拉到最下面查找password
sudo kubectl logs pod/jenkins-d6fcdfdd6-hqqvd   -n jenkins   
  1. 访问http://ip:30000
  2. Windows安装java 21
  • 下载zip
  • 解压
  • 添加JAVA_HOME环境变量,例如D:\java21sdk\jdk-21.0.1
  • 添加PATH 例如 %JAVA_HOME%\bin;
  1. 配置添加Windows节点
    启动方式选择如下
    k8s 中部署Jenkins_第1张图片

跟着配置即可

你可能感兴趣的:(k8s,Jenkins,kubernetes,jenkins)