# install jenkins ``` kubectl create -f serviceaccount.yaml helm install --name jenkins --set rbac.create=true,master.runAsUser=1000,master.fsGroup=1000 stable/jenkins ```

k8s 实验 helm jenkins deployment 部署_Docker

k8s 实验 helm jenkins deployment 部署_Docker_02

k8s 实验 helm jenkins deployment 部署_云计算_03

k8s 实验 helm jenkins deployment 部署_云计算_04

k8s 实验 helm jenkins deployment 部署_Docker_05

k8s 实验 helm jenkins deployment 部署_Docker_06

k8s 实验 helm jenkins deployment 部署_云计算_07

k8s 实验 helm jenkins deployment 部署_云计算_08

[root@k7smaster jenkins]# cat Jenkinsfile.build pipeline { agent { kubernetes { label 'helm-pod' containerTemplate { name 'helm' image 'wardviaene/helm-s3' ttyEnabled true command 'cat' } } } stages { stage('Run helm') { steps { container('helm') { git url: 'git://github.com/wardviaene/kubernetes-course.git', branch: 'master' sh ''' HELM_BUCKET=helm-rytcufor PACKAGE=demo-chart export AWS_REGION=eu-west-1 cp -r /home/helm/.helm ~ helm repo add my-charts s3://${HELM_BUCKET}/charts cd helm/${PACKAGE} helm dependency update helm package . helm s3 push --force ${PACKAGE}-*.tgz my-charts ''' } } } } }

复制jenkins pipline 进来

k8s 实验 helm jenkins deployment 部署_云计算_09

k8s 实验 helm jenkins deployment 部署_Docker_10

k8s 实验 helm jenkins deployment 部署_云计算_11

k8s 实验 helm jenkins deployment 部署_云计算_12

相同的创建部署pipline 脚本

Jenkinsfile.deploy pipeline { agent { kubernetes { label 'helm-pod' serviceAccount 'jenkins-helm' containerTemplate { name 'helm-pod' image 'wardviaene/helm-s3' ttyEnabled true command 'cat' } } } stages { stage('Run helm') { steps { container('helm-pod') { git url: 'git://github.com/wardviaene/kubernetes-course.git', branch: 'master' sh ''' HELM_BUCKET=helm-rytcufor PACKAGE=demo-chart export AWS_REGION=eu-west-1 cp -r /home/helm/.helm ~ helm repo add my-charts s3://${HELM_BUCKET}/charts DEPLOYED=$(helm list |grep -E "^${PACKAGE}" |grep DEPLOYED |wc -l) if [ $DEPLOYED == 0 ] ; then helm install --name ${PACKAGE} my-charts/${PACKAGE} else helm upgrade ${PACKAGE} my-charts/${PACKAGE} fi echo "deployed!" ''' } } } } }