由于Jenkins新版的对 Kubernetes Continuous Deploy这个插件不太友好。官网提供的新版本一直出现bug无法执行 Deploy,可以用以下我的这个老插件,不要更新新插件即可
https://www.aliyundrive.com/s/Aq71VchmAKQ
配如下
1.方式获取k8s密钥
cat .kube/config
2.导出方式或者密钥
kubectl config view --raw > k8s-config-admin
配置Jenkins连接k8s
确保可以连接
最后再配置Deploy 执行yaml,这步不用我多说了吧
最少一条pipeline也不用多说了吧,
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: jenkins
spec:
containers:
- name: docker
image: docker:19.03-dind
command:
- dockerd
- --host=unix:///var/run/docker.sock
- --host=tcp://0.0.0.0:8000
securityContext:
privileged: true
tty: true
- name: kubectl
image: registry.cn-shenzhen.aliyuncs.com/jbjb/csi:kubectl
command:
- cat
tty: true
- name: maven36
image: maven:3.6.2-jdk-8-slim
command:
- cat
tty: true
volumeMounts:
- mountPath: "/root/.m2"
name: "volume-0"
volumes:
- name: "volume-0"
persistentVolumeClaim:
claimName: "mvn"
'''
}
}
stages {
stage('Get Code && Build Package') {
steps {
container('maven36') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'http://git.rapha.top/jbjb/argo-cd.git']]])
sh 'mvn -v'
}
}
}
stage('Docker Build') {
steps {
container('docker') {
sh '''
docker build -t h5:v01 .
docker images
'''
}
}
}
stage('Deploy') {
steps {
script {
kubernetesDeploy(configs:"k8s.yaml", kubeconfigId: "kbb")
}
}
}
}
}
官网插件地址
http://updates.jenkins-ci.org/
国内源
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
|