In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article is to share with you about how to use CI/CD based on open source components, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Preface
To meet the needs of agile development, a higher standard is proposed for CI (continuous Integration) / CD (continuous delivery). Today, we will discuss how to use CI/CD based on open source components (gitlab/jenkins/harbor/kubernetes) to enable team development, operation and maintenance.
Core component name version remarks kubernetesv1.15.310.0.0.182:6443jenkins2.176.2 cluster deployment / namespace: devopsgitlab11.8 host deployment harborv1.7.4docker-compose deployment basic process
Create the corresponding project in GitLab.
The developer submits the code to GitLab.
Jenkins creates the corresponding task (Job) and integrates the project's Git address and Kubernetes cluster.
If there is a configuration hook, the Push code will automatically trigger the Jenkins build. If there is no configuration hook, you need to build it manually.
Jenkins controls Kubernetes (using the Kubernetes plug-in) to create Jenkins Slave.
Jenkins Slave performs the build according to the steps defined by the pipeline (Pipeline).
Check out code, package, compile.
Generate an image through Dockerfile.
Push the image to the private Harbor.
Jenkins once again controls Kubernetes for the latest image deployment.
Note:
The steps described above are general, and steps such as automated testing may be involved, which can be added according to the business scenario.
The above pipelining steps are generally determined by Jenkinsfile in the root directory of the application code base, and Jenkins will automatically read the file. In addition, if you need to implement strong control over a specific application pipeline, you can manage the jenkinsfile template independently, and then generate the pipeline immediately according to the jenkins API API.
The default Dockerfile is placed in the root directory of the code repository.
Component deployment
Kubernetes part 3 Kubernetes Cluster installation and deployment
Gitlab Mouji trick: teach you to build your own GitLab library hand in hand
Harbor installation configuration Guide
Jenkins
Note: this article mainly describes the deployment and configuration of jenkins, other components if you have problems with the deployment, please leave a message.
Jenkins deployment and configuration
Description:
The following yaml files are all in the / home/jenkins_deploy directory of the k8s master node
Comments on the depployment.yaml of the deployment example
NodeName ipaddress, ipaddress, please confirm that it is a valid ip.
In the example, the directory / var/jenkins_home of jenkins is mounted directly to host_path. If you have the conditions, it is recommended to replace it with shared storage.
Since the basic image of the jenkins-master is from the public network, you need a k8s maste node to access the public network, or you can push the jenkins/jenkins:lts-alpine to your private network image repository.
Comments on the ingress.yaml of the deployment example
If you also need to access the office network (outside the cluster), please change jenkins.dev.hanker.net to a valid domain name address, or you can declare service through NodePort, and you can access jenkins directly through ip:port.
1. Prepare to deploy yaml
Deployment.yaml
ApiVersion: v1kind: Namespacemetadata: name: devops# Deployment apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: devopsspec: replicas: 1 revisionHistoryLimit: 3 template: metadata: labels: app: jenkins spec: nodeName: 1.1.1.1 serviceAccountName: jenkins-admin containers:-image: jenkins/jenkins:lts-alpine imagePullPolicy: IfNotPresent name: jenkins volumeMounts:-name: jenkins-volume MountPath: / var/jenkins_home-name: jenkins-localtime mountPath: / etc/localtime env:-name: JAVA_OPTS value:'- Xms256m-Xmx1024m-Duser.timezone=Asia/Shanghai'-name: TRY_UPGRADE_IF_NO_MARKER value: 'true' ports:-name: http containerPort: 8080 -name: agent containerPort: 50000 resources: requests: cpu: 1000m memory: 1Gi limits: cpu: 1200m memory: 2Gi volumes:-name: jenkins-localtime hostPath: path: / etc/localtime-name: jenkins-volume hostPath: path: / home/jenkins/jenkins_home
Configure service, services.yaml
-apiVersion: v1kind: Servicemetadata: name: jenkins-service namespace: devopsspec: ports:-name: http protocol: 8080 targetPort: 8080-port: 50000 targetPort: 50000 name: agent selector: app: jenkins
Authorize jenkins to access rbac.yaml to K8s
ApiVersion: v1kind: ServiceAccountmetadata: labels: k8s-app: jenkins name: devops---apiVersion: rbac.authorization.k8s.io/v1beta1kind: ClusterRolemetadata: name: jenkins-rbac namespace: devopsrules:-apiGroups: ["", "extensions", "app"] resources: ["pods", "pods/exec", "deployments", "replicasets"] verbs: ["get", "list", "watch", "create", "update", "patch" "delete"]-apiVersion: rbac.authorization.k8s.io/v1beta1kind: ClusterRoleBindingmetadata: name: jenkins-admin namespace: devops labels: k8s-app: jenkinssubjects:-kind: ServiceAccount name: jenkins-admin namespace: devopsroleRef: kind: ClusterRole name: jenkins-rbac apiGroup: rbac.authorization.k8s.io
In order to facilitate access to the office network (outside the cluster), ingress.yaml
ApiVersion: extensions/v1beta1kind: Ingressmetadata: name: jenkins-ingress namespace: devopsspec: rules:-host: jenkins.dev.hanker.net http: paths:-backend: serviceName: jenkins-service servicePort: 8080 path: / 2. Apply yaml to deploy jenkins$ pwd$ / home/jenkins_deploy$ kubectl apply-f *. Yaml3. Confirm the jenkins service status [root@node0 jenkins_deploy] # kubectl-n devops get deployment jenkinsNAME READY UP-TO-DATE AVAILABLE AGEjenkins 1 Universe 1 1 1 51d [root@node0 jenkins_deploy] # 4. Access jenkins installation plug-ins, settings
Note: the domain name jenkins.dev.hanker.net declared in step 1 has been resolved to ingress, so it can be accessed directly. If you also want to access jenkins through a custom domain name, please resolve to the correct ingress service node.
Confirm that you have also installed the kubernetes/ kubernetes cli plug-in
Instructions: [Manage Jenkins]-> [Manage Plugins]
You should be able to get the jenkins-master password through similar instructions.
$kubectl-n devops exec jenkins-pod-name cat / var/jenkins_home/secrets/initialAdminPassword
Configure the Kubernetes plug-in
Instructions: [Manage Jenkins]-> [Configure System]
Marked in the figure:
Please modify it to the K8s master corresponding to your environment
Declare the command space of jenkins-agent, which can also be adjusted as needed
The access address of jenkins-master, which is accessed in the form of service-name in this example.
Test the connection with the K8s sharing group. If you get "
Connection test successful, congratulations on being able to continue.
Configure Kubernetes Pod Template
Marked in the figure:
Set the basic jenkins-agent image
Specify working directory
If you need to download, export, or cache builds, it makes sense to specify a directory for shared storage.
Set up directory mount
As mentioned in step 2, you can mount the host's directory or network storage to jenkins-agent.
The above is how to use CI/CD based on open source components. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.