k8s 中部署Jenkins

发布时间:2023年12月21日
  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/"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-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
        volumeMounts:
          - name: jenkins-vol
            mountPath: /var/jenkins_vol
        resources:
          limits:
            cpu: 500m
            memory: 2Gi
          requests:
            cpu: 500m
            memory: 2Gi
      volumes:
        - name: jenkins-vol
          persistentVolumeClaim:
            claimName: jenkins-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
文章来源:https://blog.csdn.net/weixin_43632687/article/details/135123964
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。