遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

k8s中安装jenkins

 

jenkins简介

 

Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件项目可以进行持续集成。(摘抄自百度百科)

 

官网:https://www.jenkins.io/zh/

 

 

 

编写jenkins.yaml

说明:

  容器跑起来后,jenkins的目录是/var/jenkins_home

  存储卷用的是hostPath,这里面我们指定pod调度到k8s-master01

在k8s-master01上创建目录:mkdir /data_jenkins

创建名称空间:kubectl create ns jenkins

jenkins.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: jenkins
  namespace: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      nodeName: k8s-master01
      containers:
      - name: jenkins
        image: jenkins/jenkins:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        - containerPort: 50000
          name: agent
          protocol: TCP
        resources:
          limits:
            cpu: 2000m
            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
          mountPath: /var/jenkins_home
      volumes:
      - name: jenkins-volume
        hostPath:
          path: /data_jenkins
          type: DirectoryOrCreate

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

 

另外,jenkins在容器中的uid是1000,赋予其宿主机上目录的权限:chown -R 1000.1000 /data_jenkins

 

创建资源

应用资源文件:kubectl apply -f jenkins.yaml

查看pod:kubectl get po -n jenkins -owide

 

查看svc:kubectl get svc -n jenkins

 

通过k8s集群任意一个节点访问:192.168.117.161:30667

 

进入容器查看密码:

kubectl exec -it -n jenkins po/jenkins-dd6c9cdcd-m9964 -- sh

 密码是: 1e45bee7642d44e3acd5e9563f1bebf2

也可以在宿主机上查看密码:

 

输入密码,点击“继续”

 

选择“安装推荐的插件”

 

 此步耗时较多,需要耐心等待

 

 

 

点击“继续”,创建第一个管理员用户

 

 

配置站点

也就是更改插件源为国内插件源,否则下载插件会很慢

URL中输入如下内容:

https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

点击“立即获取” 

 

 

【bak】

原文:https://www.cnblogs.com/uncleyong/p/16650216.html

 

posted @ 2022-09-03 11:32  全栈测试笔记  阅读(813)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end