前言谈到持续集成工具就离不开众所周知的Jenkins,本文带你了解如何在 Kubernetes 上安装 Jenkins , 后续文章会带你深入了解如何使用k8s pod 作为 Jenkins的build agents 。
准备需要一个running的 Kubernetes Cluster,可以参考我前面的文章 云原生之旅 - 4)基础设施即代码 使用 Terraform 创建 Kubernetes
安装
Step 1: 创建Namespace
apiVersion: v1kind: Namespacemetadata: name: jenkinsnamespace.yaml
kubectl apply -f namespace.yaml
Step 2: 创建 k8s service account and RBAC 权限
---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: jenkins-adminrules: - apiGroups: [""] resources: ["*"] verbs: ["*"]---apiVersion: v1kind: ServiceAccountmetadata: name: jenkins-admin namespace: jenkins---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: jenkins-adminroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: jenkins-adminsubjects:- kind: ServiceAccount name: jenkins-admin namespace: jenkinsserviceAccount.yaml
kubectl apply -f serviceAccount.yamlStep 3: 创建 StorageClass 和 PersistentVolumeClaim(我的例子是在GCP上面 , 其它云提供商类似)
---## if not create StorageClass, default to use standard StorageClassapiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: jenkins-sc namespace: jenkinsprovisioner: kubernetes.io/gce-pdvolumeBindingMode: ImmediateallowVolumeExpansion: truereclaimPolicy: Deleteparameters: type: pd-standard fstype: ext4 replication-type: none---apiVersion: v1kind: PersistentVolumeClaimmetadata: name: jenkins-storage namespace: jenkinsspec: storageClassName: jenkins-sc accessModes: - ReadWriteOnce resources: requests: storage: 20Givolume.yaml
- Create a storage class
- Provision a Persistent volume using the storage class.
kubectl get pvc -n jenkinsNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEjenkins-storage Bound pvc-27efe7b9-c963-4366-b100-a3b01bb25666 20Gi RWO jenkins-sc 23sStep 4: 创建 Deployment
Jenkins home 目录需要mount,不然 Jenkins pod 一旦重启的话,数据会丢失 。
apiVersion: apps/v1kind: Deploymentmetadata: name: jenkins namespace: jenkinsspec: replicas: 1 selector: matchLabels: app: jenkins-server template: metadata: labels: app: jenkins-server spec: securityContext: fsGroup: 1000 runAsUser: 1000 serviceAccountName: jenkins-admin containers: - name: jenkins image: jenkins/jenkins:lts resources: limits: memory: "2Gi" cpu: "1000m" requests: memory: "500Mi" cpu: "500m" ports: - name: httpport containerPort: 8080 - name: jnlpport containerPort: 50000 livenessProbe: httpGet: path: "/login" port: 8080 initialDelaySeconds: 90 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 5 readinessProbe: httpGet: path: "/login" port: 8080 initialDelaySeconds: 60 periodSeconds: 10 timeoutSeconds: 5 failureThreshold: 3 volumeMounts: - name: jenkins-data mountPath: /var/jenkins_home volumes: - name: jenkins-data persistentVolumeClaim: claimName: jenkins-storage
推荐阅读
- 问道手游探案镖局风云任务完成图文攻略
- 又拍云之 Keepalived 高可用部署
- 我的Vue之旅 10 Gin重写后端、实现页面详情页 Mysql + Golang + Gin
- 云顶之弈8月11日12.15版本更新维护公告
- 京东云开发者|mysql基于binlake同步ES积压解决方案
- 奥比岛2022盛夏之旅活动参与方法
- 京东云开发者|软件架构可视化及C4模型:架构设计不仅仅是UML
- 奥比岛:梦想国度暗夜袭击魔药店失窃疑云答案是什么
- 云原生之旅 - 9)云原生时代网关的后起之秀Envoy Proxy 和基于Envoy 的 Emissary Ingress
- 华为云 MRS 基于 Apache Hudi 极致查询优化的探索实践