Build and Deploy a Go Project
- You need to enable the KubeSphere DevOps System.
- You need to create a workspace, a DevOps project, a project, and a user (). This account needs to be invited to the DevOps project and the project for deploying your workload with the role
operator
. For more information, see .
Create a Docker Hub Access Token
Click Security in the left navigation pane and then click New Access Token.
In the displayed dialog box, enter a token name (
go-project-token
) and click Create.Click Copy and Close and make sure you save the access token.
You need to create credentials in KubeSphere for the access token created so that the pipeline can interact with Docker Hub for imaging pushing. Besides, you also create kubeconfig credentials for the access to the Kubernetes cluster.
Log in to the web console of KubeSphere as . In your DevOps project, go to Credentials under DevOps Project Settings and then click Create on the Credentials page.
In the displayed dialog box, set a Name, which is used later in the Jenkinsfile, and select Username and password for Type. Enter your Docker Hub account name for Username and the access token just created for Password/Token. When you finish, click OK.
For more information about how to create credentials, see .
Click Create again and select kubeconfig for Type. Note that KubeSphere automatically populates the Content field, which is the kubeconfig of the current user account. Set a Name and click OK.
Create a Pipeline
With the above credentials ready, you can create a pipeline using an example Jenkinsfile as below.
Set a name in the displayed dialog box and click Next.
In this tutorial, you can use default values for all the fields. On the Advanced Settings tab, click Create.
Copy and paste all the content below to the displayed dialog box as an example Jenkinsfile for your pipeline. You must replace the value of
DOCKERHUB_USERNAME
,DOCKERHUB_CREDENTIAL
, , andPROJECT_NAME
with yours. When you finish, click OK.
Note
If your pipeline runs successfully, images will be pushed to Docker Hub. If you are using Harbor, you cannot pass the parameter to docker login -u
via the Jenkins credential with environment variables. This is because every Harbor robot account username contains a character, which will be converted to $$
by Jenkins when used by environment variables. .
Run the Pipeline
After you finish the Jenkinsfile, you can see graphical panels are displayed on the dashboard. Click Run to run the pipeline.
In Run Records, you can see the status of the pipeline. It may take a while before it successfully runs.
A Deployment is created in the project specified in the Jenkinsfile if the pipeline runs successfully.