Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install jenkins for helm

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to install jenkins on helm". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to install jenkins on helm"!

The actual namespace.

This actual combat uses a namespace named helm-jenkins and executes the following command to create it:

kubectl create namespace helm-jenkins Create PV

In order for the jenkins service to start smoothly, pv needs to be deployed in advance:

Create a new file called pv-helm-jenkins.yaml with the following content:

apiVersion: v1kind: PersistentVolumemetadata: name: helm-jenkins namespace: helm-jenkinsspec: capacity: storage: 10Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle nfs: path: /usr/local/work/test/002 server: 192.168.133.142

Execute kubectl create -f pv-helm-jenkins.yaml to create pv

Check if the PV is ready:

[root@node1 helm-jenkins]# kubectl get pvNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEhelm-jenkins 10Gi RWO Recycle Available 5s 14hhelm install jenkins

Make sure helm2.16.1 is installed and working correctly:

[root@node1 helm-jenkins]# helm versionClient: &version.Version{SemVer:"v2.16.1", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}Server: &version.Version{SemVer:"v2.16.1", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}

Make sure that the following helm repo is ready (if none can be added via helm repo add):

[root@node1 helm-jenkins]# helm repo listNAME URL stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

Execute the following command to create jenkins deployment, service and other resources:

helm install --namespace helm-jenkins --name my-jenkins stable/jenkins

After execution, the console outputs the following:

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);echo2. 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/login3. Login with the password from step 1 and the username: admin

The first item above gives an important hint: To get the admin account password, execute the command:

printf $(kubectl get secret --namespace helm-jenkins my-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo

As shown in the red box below, I got the admin password here as Eq6WxHvJ2V:

Checking the services, we found that there are two services under the helm-jenkins namespace: my-jenkins and my-jenkins-agent. The former is the jenkins website, and the latter is used to receive the registration of jenkins instances that perform tasks:

[root@node1 helm-jenkins]# kubectl get svc -n helm-jenkinsNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEmy-jenkins LoadBalancer 10.233.10.35 8080:31763/TCP 31mmy-jenkins-agent ClusterIP 10.233.35.20 50000/TCP 31m

my-jenkins This service type is LoadBalancer, port 8080 is mapped to host 31763, so use the IP of a host in the kubernetes cluster, plus port 31763 to access it through the browser, as shown below:

At this point, the jenkins installation is complete, and the next step is to make the necessary settings.

Set up kubernetes plugin

In order for Jenkins to work in the following modes, you also need to set up the kubernetes plugin

Click "Manage Jenkins" in the red box below to enter the settings page

Because many plug-ins are older versions, there will be upgrade prompts on the page, which are temporarily unavailable here, so click "Configure System" in the red box below.

Click the "Test Connection" button in red box 1 below, and you will see the error message in red box 2:

The reason for the above error is that the jenkins container does not have permission to access the api server of kubernetes. In order to solve this problem, we must first find out the identity of the container. We know that the container has its own serviceaccount in the kubernetes environment. Execute the command kubectl get serviceaccount -n helm-jenkins to view the serviceaccount under the current namespace:

[root@node1 helm-jenkins]# kubectl get serviceaccount -n helm-jenkinsNAME SECRETS AGEdefault 1 3h65m

The jenkins container's serviceaccount is default

Knowing the serviceaccount of the container, the above problem is easy to solve. We use RBAC to bind the permissions required to access the api server to default. In order to save trouble, we do not list the permissions one by one. Next, we directly give default the highest permissions (do not do this in production environment, you must assign them as needed);

Create a new file called rbac-helm-jenkins-default.yaml with the following contents:

apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: rbac-helm-jenkins-default namespace: helm-jenkinsroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-adminsubjects:- kind: ServiceAccount name: default namespace: helm-jenkins

RBAC takes effect by executing the command kubectl create -f rbac-helm-jenkins-default.yaml

Go back to the previous page again and click the "Test Connection" button, as shown in the following figure, prompting "Connection successful":

Next, set the Pod template parameters, as shown in the following figure. namepsace should be set to helm-jenkins, and the value of Labels my-jenkins-jenkins-slave should be recorded.

Click the "Save" button at the bottom to make the settings take effect:

After setting up, create a task to experience the jenkins function on kubernetes

Experience Freestyle project

Create a Freestyle project, as shown below:

As shown in the figure below, the value of Label Expression in the form is my-jenkins-jenkins-slave written down earlier.

As shown below, the specific content of this task is very simple. Execute a shell and output "Hello World!" ":

Click on the "Save" button at the bottom to save

Click "Build Now" in the red box below to start building

At this point, go to the console and execute the command kubectl get pods -n helm-jenkins to check the pod. You will find that a new pod appears, as shown below. This is the pod that executes the jenkins task:

[root@node1 helm-jenkins]# kubectl get pods -n helm-jenkinsNAME READY STATUS RESTARTS AGEdefault-66vcq 0/1 ContainerCreating 0 1smy-jenkins-74bcdfc566-jbw28 1/1 Running 0 5h6m

Return to jenkins page, visible task has been executed

At this point, I believe that everyone has a deeper understanding of "how to install jenkins on helm". You may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report