James, a Java engineer, enjoys learning and documenting current hot technologies and verifying their advantages and disadvantages, as well as the implementation and promotion of current hot cloud native solutions.
preface
Designed specifically for CI/CD workflows in Kubernetes, the Jenkins based KubeSphere DevOps system provides a one-stop solution to help development and operations teams build, test, and release applications to Kubernetes in a very simple way. It also has plug-in management, binary-to-image (B2I), source-to-image (S2I), code dependency cache, code quality analysis, pipeline logging and other functions.
DevOps systems provide users with an automated environment where applications can be automatically published to the same platform. It is also compatible with third party private images warehouse (such as Harbor) and the code base (e.g. GitLab/lot/SVN/BitBucket). It provides users with a comprehensive, visual CI/CD pipeline, creating a great user experience, and this compatible pipeline capability is very useful in offline environments.
In short, DevOps helps us pull code, compile projects, build images, push images, and deploy projects in a fully automated package.
On how to install the conversation function, please refer to: kubesphere. IO/useful/docs/plu…
Create DevOps project && Create pipeline
Create DevOps Project: Enterprise Space – >DevOps Project – > Create; Enter the project name and click OK.
Create pipeline: Click the DevOps project you just created, go to the pipeline menu, click Create, and enter the pipeline name.
Code warehouse can fill in also can not fill, fill out now there will be a webhook address, this address can be set to the Git (or other) warehouse warehouse have code submitted to automatically run our assembly line, rather then a callback, so you may submit the project’s deployment code is a fully automatic process.
So here we first demonstrate the situation of not filling, fill in the pipeline name and click next, click Create.
Editing line
Click on the line created just now to enter, click Edit Line:
As you can see, there are two sets of templates. Here we select the second set and click Save:
To see the effect, then we click edit Pipeline:
When you come in, you can see that there is an agent on the right, with agent Type and agent lable below it. The proxy type is node. The following lable has four options: base, go, Maven, nodejs:
- If we are java-related project packaging, then we can choose Maven;
- Nodejs can be used for front-end projects;
- If it is go language development can choose go;
- If it’s something else then you can select Base;
Website: kubesphere. IO/useful/docs/dev…
Here the small editor is deploying a Java project, so I chose Maven;
1. Pull code
- Step 1: Click to see the window on the right;
- Step 2: Enter the name of the phase
- Step 3: Remove the specified Base container, because we will be using the Maven container
Click Add Steps:
Select the specified container:
Fill in the container name and click OK:
Click Add Nesting step:
Pull code through git, or if you’re SVN, checkout. The editor uses Git.
Fill in the GIE warehouse Url and branch, then click New Credential:
- Enter the credential ID: this is arbitrary;
- Type: Select account certificate;
- User name: Git user name
- Token/Password: Git password
And then HIT OK, OK.
To display the drop-down code directory, add a nested step:
Then click OK and Save.
When you’re done, you can hit Run and see what happens.
2. Project compilation
After running, we click edit pipeline again, click the second step, and fill in the name: Project Compile.
To specify maven containers, add nested steps: shell script, type Maven packaging command:
$ mvn clean package -Dmaven.test.skip=true
Copy the code
Click OK, click Save, you can also run to see the effect, whether it is successful.
3. Build an image
After running, we click edit pipeline again, click the third step, and fill in the name: Build image; Select the agent type: None.
Also specify maven container, add nested steps: shell script, type command, display directory files:
ls isee-gateway/target
Copy the code
Enter docker build image command:
$ docker build -t isee-gateway:latest -f isee-gateway/Dockerfile isee-gateway/
Copy the code
Parameter description: isee-gateway:latest: the image name has been labeled. -f: Specifies the Dockerfile file to build isee-gateway/ : in this directory
In practice, we can’t build one image at a time, we can have multiple or dozens of microservices that need to be mirrored, so we can add parallel steps here, and then continue with the above steps:
4. Push an image
So once we’re done we go to edit pipeline again, step four,
- Enter name: Push image; (We will push the image to ali Cloud mirror warehouse, of course, you can also push to other warehouses or private warehouses)
- Select the agent type: None
The same way you specify maven containers, add nested steps: Add credentials
Click OK, select the credentials we just created after creation, and fill in the username and password variables (it means to use the username and password as a variable, and then log in to Ali Cloud warehouse, push mirror and other operations can use this variable, so there is no need to manually enter the username and password).
To add nested steps, select shell script and enter the following content (here we use username and password variables) :
$ echo "$DOCKER_PWD_VAR" | docker login $REGISTRY -u "$DOCKER_USER_VAR" --password-stdin
Copy the code
To add a nested step, select a shell script and enter the following:
$ docker tag isee-gateway:latest $REGISTRY/$DOCKERHUB_NAMESPACE/isee-gateway:SNAPSHOT-$BUILD_NUMBER
Copy the code
To add a nested step, select a shell script and enter the following:
$ docker push $REGISTRY/$DOCKERHUB_NAMESPACE/isee-gateway:SNAPSHOT-$BUILD_NUMBER
Copy the code
Of course, it is possible to add parallel steps and push multiple images to the repository at the same time.
DOCKER_PWD_VAR and DOCKER_USER_VAR are used as REGISTRY variables. Where is the definition?
After saving the pipeline, click Edit Jenkinsfile:
At the bottom, we can see that the REGISTRY variable is defined. We just need to change the value of the REGISTRY variable to the address of our Ali Cloud warehouse
When you’re done, save it and run it to see if it worked.
Deployment of 5.
Follow the old rules:
Follow the steps to continue:
New certificate:
There is a voucher ID that needs to be filled in above, how should I fill in this?
Save the pipeline, click Edit Jenkinsfile, and the variable at the bottom is KUBECONFIG_CREDENTIAL_ID. The value of the variable is demo-kubeconfig.
Once you have created your credentials, click OK and you are done.
Save the assembly line, click run, so far, a set of assembly line editing is complete!
This article is published by OpenWrite!