一、Jenkins简介

引用官方的话来说:
Jenkins是开源CI&CD软件领导者, 提供超过1000个插件来支持构建、部署、自动化, 满足任何项目的需要。

二、安装Jenkins

使用Helm安装

添加仓库并更新:

  1. helm repo add jenkins https://charts.jenkins.io
  2. helm repo update

先创建一个namespace,以免默认添加到default:

  1. kubectl create ns jenkins

部署Jenkins

  1. helm install jenkins jenkins/jenkins -n jenkins

部署完,会在控制台中打印:

  1. NAME: jenkins
  2. LAST DEPLOYED: Sun Nov 1 15:26:12 2020
  3. NAMESPACE: jenkins
  4. STATUS: deployed
  5. REVISION: 1
  6. NOTES:
  7. 1. Get your 'admin' user password by running:
  8. printf $(kubectl get secret --namespace jenkins jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
  9. 2. Get the Jenkins URL to visit by running these commands in the same shell:
  10. export POD_NAME=$(kubectl get pods --namespace jenkins -l "app.kubernetes.io/component=jenkins-master" -l "app.kubernetes.io/instance=jenkins" -o jsonpath="{.items[0].metadata.name}")
  11. echo http://127.0.0.1:8080
  12. kubectl --namespace jenkins port-forward $POD_NAME 8080:8080
  13. 3. Login with the password from step 1 and the username: admin
  14. 4. Use Jenkins Configuration as Code by specifying configScripts in your values.yaml file, see documentation: http:///configuration-as-code and examples: https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos
  15. For more information on running Jenkins on Kubernetes, visit:
  16. https://cloud.google.com/solutions/jenkins-on-container-engine
  17. For more information about Jenkins Configuration as Code, visit:
  18. https://jenkins.io/projects/jcasc/

使用YAML安装

创建命名空间

首先创建一个命名空间,命名为jenkins:

apiVersion: v1
kind: Namespace
metadata:
  name: jenkins

创建服务

创建一个服务:

apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: jenkins
spec:
  type: ClusterIP
  ports:
    - port: 8080
      targetPort: 8080
  selector:
    jenkins-app: jenkins