k8s安装jenkins

前天 14:00
阅读数 18


创建自己的空间

cat 01-jenkins-ns.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: jenkins-k8s

cat 02-jenkins-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-k8s-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteMany
  nfs:
    server: 172.16.10.222
    path: /data/jenkins

cat 03-jenkins-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-k8s-pvc
  namespace: jenkins-k8s
spec:
  resources:
    requests:
      storage: 10Gi
  accessModes:
    - ReadWriteMany

cat 04-jenkins-account.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: jenkins-k8s-sa
  namespace: jenkins-k8s

cat 05-jenkins-cluster-role-binding.yaml

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: jenkins-k8s-sa-cluster
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: jenkins-k8s-sa
  namespace: jenkins-k8s

cat 06-jenkins-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: jenkins-k8s
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      serviceAccount: jenkins-k8s-sa
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        - containerPort: 50000
          name: agent
          protocol: TCP
        resources:
          limits:
            cpu: 1000m
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 512Mi
        livenessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        readinessProbe:
          httpGet:
            path: /login
            port: 8080
          initialDelaySeconds: 60
          timeoutSeconds: 5
          failureThreshold: 12
        volumeMounts:
        - name: jenkins-volume
          subPath: jenkins-home
          mountPath: /var/jenkins_home
      volumes:
      - name: jenkins-volume
        persistentVolumeClaim:
          claimName: jenkins-k8s-pvc

cat 07-jenkins-service.yaml

apiVersion: v1 
kind: Service
metadata:
  name: jenkins-service
  namespace: jenkins-k8s
  labels:
    app: jenkins 
spec: 
  selector: 
    app: jenkins 
  type: NodePort 
  ports: 
  - name: web 
    port: 8080 
    targetPort: web 
    nodePort: 30012 
  - name: agent 
    port: 50000 
    targetPort: agent


密码在自己映射的路径下,我自己nfs的路径是

/data/jenkins/jenkins-home/secrets

cat initialAdminPassword
85b3fe48c3884993b7147a4977ab113a

点击推荐就行

图片.png

创建用户

图片.png

下一步

图片.png

保存并完成

图片.png

开始使用

图片.png

然后就可以配置了

安装k8s插件

Manage Jnekins------>插件管理------>可选插件------>搜索kubernetes------>
出现如下
图片.png

下一步,需要搜索才会显示

图片.png

直接安装

图片.png

安装完勾中安装完击重启,然后用创建好的密码登录


配置jenkins对接k8s

图片.png

图片.png

配置完连接测试

图片.png

配置pods模板

图片.png


docker镜像:cnych/jenkins.jnlp

工作目录:/home/jenkins

保存就行,然后就可以写pipline构建自己的代码了。




展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部