Kubernetes cluster Helm Chart installs Jenkins and sets Simplified Chinese

Kubernetes cluster Helm Chart installs Jenkins and sets Simplified Chinese

This article describes how to quickly install Jenkins in the Kubernetes environment through Helm Chart, and expose the service to the outside world through Ingress. It will also introduce how to install the Jenkins Chinese plugin.

The role of Jenkins

Jenkins is an open source continuous integration/continuous deployment (CI/CD) tool for automating various tasks including building, testing and deploying software. Jenkins is an important tool to help automate repetitive tasks such as building, testing, and deployment in the software development process. It can improve work efficiency, reduce human errors, speed up the development cycle, and ultimately improve the quality and delivery speed of software. Jenkins is mainly used in the following aspects of the development process:

  • Continuous Integration (Continuous Integration) : Jenkins can monitor changes in your version control system, automatically compile and test code, and enable developers to quickly find and solve problems.
  • Continuous Deployment (Continuous Delivery/Deployment) : Jenkins can also automatically deploy software to the production environment, or other preset environments. This makes the process of delivering updates and new releases quicker and easier.
  • Testing and Reporting : Jenkins can perform various types of tests and generate detailed test reports. These reports can be viewed on the Jenkins web interface.
  • Distributed builds : Jenkins can distribute work across multiple machines, allowing larger projects to be built and tested in less time.
  • Plug-in system : Jenkins has a huge plug-in ecosystem, which allows Jenkins to meet the needs of almost any CI/CD scenario by installing plug-ins.

1. Helm Chart install Jenkins 2.332.3

1.1 Prerequisites

a. Helm version >=v3.2.0, for the installation of Helm, please refer to: Helm Install

b. A default StorageClass is required. For the specific preparation process, please refer to: Install StorageClass on Kubernetes

c. There are default IngressClasses. For specific preparation process, please refer to: Install IngressClass in Kubernetes . Step 4 "Set as default Ingress Class" is necessary. At the same time, it is best to set the NodePort port of Ingress to 80 or 443

1.2 Installation process

a. Create the installation directory

#切换到当前用户根目录并建立jenkins文件夹
cd ~ && mkdir jenkins

cd jenkins

b. Create a jenkins namespace, an independent namespace helps resource management

kubectl create ns jenkins

c. Add jenkins official repo warehouse

helm repo add jenkinsci https://charts.jenkins.io/


d. If you need to do some customization when installing jenkins, please refer to the official values.yaml file, where each parameter will be described in detail: official website reference

helm pull jenkinsci/jenkins --version 4.1.3

tar -xvf jenkins-4.1.3.tgz

cd jenkins

# 我主要对Jenkins的初始化密码、服务暴露方式设置为Ingress、数据持久化绑定StorageClass。
vi values.yaml
#初始化密码,搜索 "adminPassword" 关键字(不设置,系统会生成一个默认的,通过Pod可以查看)
adminPassword: "<your password>"

#服务暴露方式设置为Ingress,搜索 "ingress:" 关键字,设置为如下
  ingress:
    enabled: true #开启
    paths: []
    # For Kubernetes v1.14+, use 'networking.k8s.io/v1beta1'
    # For Kubernetes v1.19+, use 'networking.k8s.io/v1'
    apiVersion: "networking.k8s.io/v1"
    labels: {
    
    }
    annotations: {
    
    }
    ingressClassName: nginx #Ingress的名称
    hostName: jenkins.yiqi.com
    #如果需要可以设置tls,这样即可通过https登录是就会有相应证书。由于我是自己测试,ingress后续会和很多系统做集成,使用非授信的ssl证书反而会带来很多麻烦。
    # tls:
    # - secretName: jenkins.cluster.local
    #   hosts:
    #     - jenkins.cluster.local

#数据持久化绑定StorageClass,搜索 "persistence:" 关键字,设置为如下
  enabled: true
  existingClaim:
  storageClass: "nfs-client" #设置为StorageClass名称
  annotations: {
    
    }
  labels: {
    
    }
  accessMode: "ReadWriteOnce"
  size: "8Gi"
  volumes:
  mounts:

e. Execute the installation command

cd ~/jenkins

helm install jenkins ./jenkins -n jenkins

#成功后看到如下提示
NAME: jenkins
LAST DEPLOYED: Thu Jun 15 08:47:45 2023
NAMESPACE: jenkins
STATUS: deployed
REVISION: 2
NOTES:
1. Get your 'admin' user password by running: #查看默认admin用户密码
  kubectl exec --namespace jenkins -it svc/jenkins -c jenkins -- /bin/cat /run/secrets/chart-admin-password && echo

2. Visit http://jenkins.yiqi.com

3. Login with the password from step 1 and the username: admin
4. Configure security realm and authorization strategy
5. Use Jenkins Configuration as Code by specifying configScripts in your values.yaml file, see documentation: http://jenkins.yiqi.com/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/


NOTE: Consider using a custom image with pre-installed plugins

#通过如下命令检测&确保Pod正确运行,容器会经历两个init阶段,故启动需要一定时间
kubectl get po -n jenkins -w
NAME        READY   STATUS    RESTARTS      AGE
jenkins-0   2/2     Running   2 (15h ago)   15h

2. Log in to the graphical interface and set Chinese

2.1 Set the Chinese interface

a. Log in to the home page
insert image description here
b. Click "Manage Jenkins"
insert image description here
c. Search for the "Chinese" keyword under "Available", check the "Restart" selection box during installation, restart the service after completion, and log in again to see the Chinese interface.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_46660849/article/details/131246977