本篇内容主要讲解“helm怎么安装jenkins”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“helm怎么安装jenkins”吧!
本次实战的namespace
本次实战使用名为helm-jenkins的namespace,执行以下命令创建:
kubectl create namespace helm-jenkins
创建PV
为了后面的jenkins服务顺利启动,需要预先部署好pv:
apiVersion: v1
kind: PersistentVolume
metadata:
name: helm-jenkins
namespace: helm-jenkins
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /usr/local/work/test/002
server: 192.168.133.142
[root@node1 helm-jenkins]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
helm-jenkins 10Gi RWO Recycle Available 5s
14h
helm安装jenkins
[root@node1 helm-jenkins]# helm version
Client: &version.Version{SemVer:"v2.16.1", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.1", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}
[root@node1 helm-jenkins]# helm repo list
NAME URL
stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm install --namespace helm-jenkins --name my-jenkins stable/jenkins
NOTES:
1. Get your 'admin' user password by running:
printf $(kubectl get secret --namespace helm-jenkins my-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:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc --namespace helm-jenkins -w my-jenkins'
export SERVICE_IP=$(kubectl get svc --namespace helm-jenkins my-jenkins --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
echo http://$SERVICE_IP:8080/login
3. Login with the password from step 1 and the username: admin
上述内容的第一条给出了重要提示:获取admin账号密码的方法,执行命令即可:
printf $(kubectl get secret --namespace helm-jenkins my-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
如下图红框所示,我这里得到了admin密码为Eq6WxHvJ2V:
[root@node1 helm-jenkins]# kubectl get svc -n helm-jenkins
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-jenkins LoadBalancer 10.233.10.35 <pending> 8080:31763/TCP 31m
my-jenkins-agent ClusterIP 10.233.35.20 <none> 50000/TCP 31m
设置kubernetes插件
为了让jenkins在以下模式工作,还需要设置kubernetes插件
点击下图红框中的"Manage Jenkins",进入设置页面
由于很多插件版本较久,页面上会有升级提示,这里暂时用不到,因此直接点击下图红框中的"Configure System"
点击下图红框1中的"Test Connection”按钮,您会见到红框2中的错误信息:
产生上述错误的原因,是由于jenkins容器没有权限访问kubernetes的api server导致的,为了解决此问题,要先搞清楚容器的身份,我们知道容器在kubernetes环境中都有自己的serviceaccount,执行命令kubectl get serviceaccount -n helm-jenkins查看当前namespace下的serviceaccount:
[root@node1 helm-jenkins]# kubectl get serviceaccount -n helm-jenkins
NAME SECRETS AGE
default 1 3h65m
可见jenkins容器的serviceaccount是default
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: rbac-helm-jenkins-default
namespace: helm-jenkins
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: default
namespace: helm-jenkins
执行命令kubectl create -f rbac-helm-jenkins-default.yaml使得RBAC生效
再次回到之前的页面点击"Test Connection"按钮,如下图,提示"Connection successful":
接下来设置Pod模板参数,如下图,namepsace要设置为helm-jenkins,另外要记下来Labels的值my-jenkins-jenkins-slave,后面会用到
点击底部的"Save"按钮,使设置生效:
设置完毕,接下来创建任务体验一下kubernetes上的jenkins功能
体验Freestyle project
创建一个Freestyle project,如下图:
如下图,表单中Label Expression的值是前面记下来的my-jenkins-jenkins-slave
如下图,本次任务的具体内容很简单,执行一段shell,输出"Hello World!":
点击底部的"Save"按钮保存
点击下图红框中的"Build Now",即可开始构建
此时去控制台执行命令kubectl get pods -n helm-jenkins查看pod,会发现有新的pod出现,如下所示,这是执行jenkins任务的pod:
[root@node1 helm-jenkins]# kubectl get pods -n helm-jenkins
NAME READY STATUS RESTARTS AGE
default-66vcq 0/1 ContainerCreating 0 1s
my-jenkins-74bcdfc566-jbw28 1/1 Running 0 5h6m
到此,相信大家对“helm怎么安装jenkins”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!