1. 部署jenkins

1.1 部署jenkins server

准备jenkins docker镜像

修改docker仓库地址为国内,下载速度快点,/etc/docker/daemon.json文件中增加:“registry-mirrors”: [“http://abcd1234.m.daocloud.io/”]

docker pull jenkins/jenkins

创建jenkins server,使用本地存储

1)host上供jenkins容器挂载的目录需要配置为jenkins权限,不然jenkins无法启动,1000为jenkins账户的uid
sudo chown -R 1000:1000 volume_path

2)pv
hostname的values为部署jenkins master所在主机的hostname

apiVersion: v1
kind: PersistentVolume
metadata:
  name: jenkins-master-pv
spec:
  capacity:
    storage: 30Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: local-storage
  local:
    path: /home/jenkins-master
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - k8s-node1

3)pvc

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-master-local-claim
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  storageClassName: local-storage

3)创建deployment和service

#-----Deployment----------------
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
spec:
  replicas: 2                #副本数为1
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      labels:
        app: jenkins
    spec:
      containers:
        - name: jenkins
          image: docker.io/jenkins/jenkins:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              name: http
            - containerPort: 50000
              name: jenkins-agent
          volumeMounts:
            - name: jenkins-master-vol
              mountPath: /var/jenkins_home
      volumes:
        - name: jenkins-master-vol
          persistentVolumeClaim:
            claimName: jenkins-master-local-claim
#------service---------------
apiVersion: v1
kind: Service
metadata:
  name: jenkins
spec:
  type: NodePort
  ports:
  - name: jenkins
    port: 8080
    name: http
    targetPort: 8080
    nodePort: 30009         #开启nodeport
  - name: jenkins-agent
    port: 50000
    targetPort: 50000
    nodePort: 30010
  selector:
    app: jenkins

4)创建rbac授权

初始化jenkins server

  1. 如果继承老的workspace,不需要执行此步骤
    初始化jenkins参考: http://www.mamicode.com/info-detail-2395717.html

  2. jenkins插件更新地址可以使用国内镜像站点,插件下载速度会快很多
    http://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

配置jenkins server

  1. 安装Kubernetes plugin
    在【系统管理】-【系统设置】-【新增一个云】-【Kubernetes】配置k8s的插件

jenkins配置参考: https://blog.51cto.com/ylw6006/2159769

jenkins server数据迁移

包括config.xml文件以及jobs、users、workspace、plugins四个目录,拷贝到新的workspace目录下,重启jenkins master服务

1.2 部署jenkins agent

通过jnlp的方式部署jenkins agent,以jenkins/jnlp-slave为基础镜像编写Dockerfile,制作各种编译环境的jenkins agent。

根据Android编译打包数据分离方案:

1. 工具、key等空间占用小的打包到docker镜像中
2. Android sdk、编译工具通过local volume挂载
3. 代码通过local volume方式挂载,一个pod镜像挂载一份
4. 编译脚本通过分布式存储方式挂载,分布式存储中通过git管理,各个pod读取一份
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐