一、Jenkins简介
引用官方的话来说:
Jenkins是开源CI&CD软件领导者, 提供超过1000个插件来支持构建、部署、自动化, 满足任何项目的需要。
二、安装Jenkins
使用Helm安装
添加仓库并更新:
helm repo add jenkins https://charts.jenkins.io
helm repo update
先创建一个namespace,以免默认添加到default:
kubectl create ns jenkins
部署Jenkins:
helm install jenkins jenkins/jenkins -n jenkins
部署完,会在控制台中打印:
NAME: jenkins
LAST DEPLOYED: Sun Nov 1 15:26:12 2020
NAMESPACE: jenkins
STATUS: deployed
REVISION: 1
NOTES:
1. Get your 'admin' user password by running:
printf $(kubectl get secret --namespace jenkins jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
2. Get the Jenkins URL to visit by running these commands in the same shell:
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}")
echo http://127.0.0.1:8080
kubectl --namespace jenkins port-forward $POD_NAME 8080:8080
3. Login with the password from step 1 and the username: admin
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
For more information on running Jenkins on Kubernetes, visit:
https://cloud.google.com/solutions/jenkins-on-container-engine
For more information about Jenkins Configuration as Code, visit:
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