k8s 中部署Jenkins

  1. 创建namespace
yaml 复制代码
apiVersion: v1
kind: Namespace
metadata:
  name: jenkins
  1. 创建pv以及pvc
yaml 复制代码
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
yaml 复制代码
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
yaml 复制代码
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节点
    启动方式选择如下

跟着配置即可

相关推荐
Python私教17 分钟前
ubuntu搭建k8s环境详细教程
linux·ubuntu·kubernetes
O&REO2 小时前
单机部署kubernetes环境下Overleaf-基于MicroK8s的Overleaf应用部署指南
云原生·容器·kubernetes
politeboy2 小时前
k8s启动springboot容器的时候,显示找不到application.yml文件
java·spring boot·kubernetes
运维小文3 小时前
K8S资源限制之LimitRange
云原生·容器·kubernetes·k8s资源限制
登云时刻3 小时前
Kubernetes集群外连接redis集群和使用redis-shake工具迁移数据(二)
redis·容器·kubernetes
wuxingge11 小时前
k8s1.30.0高可用集群部署
云原生·容器·kubernetes
志凌海纳SmartX12 小时前
趋势洞察|AI 能否带动裸金属 K8s 强势崛起?
云原生·容器·kubernetes
锅总12 小时前
nacos与k8s service健康检查详解
云原生·容器·kubernetes
BUG弄潮儿13 小时前
k8s 集群安装
云原生·容器·kubernetes
颜淡慕潇15 小时前
【K8S系列】kubectl describe pod显示ImagePullBackOff,如何进一步排查?
后端·云原生·容器·kubernetes