Create a Multi-cluster Pipeline
This tutorial demonstrates how to create a multi-cluster pipeline on KubeSphere.
- You need to have three Kubernetes clusters with KubeSphere installed. Choose one cluster as your host cluster and the other two as your member clusters. For more information about cluster roles and how to build a multi-cluster environment on KubeSphere, refer to Multi-cluster Management.
- You need to on your host cluster.
- You need to integrate SonarQube into your pipeline. For more information, refer to Integrate SonarQube into Pipelines.
- You need to create four accounts on your host cluster: ,
ws-admin
,project-admin
, andproject-regular
, and grant these accounts different roles. For more information, refer to .
This tutorial uses three clusters to serve as three isolated environments in the workflow. See the diagram as below.
The three clusters are used for development, testing, and production respectively. Once codes get submitted to a Git repository, a pipeline will be triggered to run through the following stages—Unit Test
, SonarQube Analysis
, Build & Push
, and Deploy to Development Cluster
. Developers use the development cluster for self-testing and validation. When developers give approval, the pipeline will proceed to the stage of Deploy to Testing Cluster
for stricter validation. Finally, the pipeline, with necessary approval ready, will reach the stage of Deploy to Production Cluster
to provide services externally.
See the table below for the role of each cluster.
Note
These Kubernetes clusters can be hosted across different cloud providers and their Kubernetes versions can also vary. Recommended Kubernetes versions for KubeSphere 3.2.0: v1.19.x, v1.20.x, v1.21.x, and v1.22.x (experimental).
Step 2: Create a workspace
Log in to the web console of the host cluster as
ws-manager
. On the Workspaces page, click Create.On the Basic Information page, name the workspace , select
ws-admin
for Administrator, and click Next.On the Cluster Settings page, select all three clusters and click Create.
Log out of the console and log back in as
project-admin
. Go to the DevOps Projects page and click Create.In the displayed dialog box, enter
multicluster-demo
for Name, select host for Cluster Settings, and then click OK.Note
Only clusters with the DevOps component enabled will be available in the drop-down list.
The DevOps project created is displayed in the list. Make sure you invite the
project-regular
user to this project and assign it theoperator
role. For more information, refer to .
Step 4: Create projects on clusters
You must create the projects as shown in the table below in advance. Make sure you invite the user to these projects and assign it the operator
role. For more information about how to create a project, refer to .
Cluster Name | Usage | Project Name |
---|---|---|
host | Testing | kubesphere-sample-prod |
shire | Production | kubesphere-sample-prod |
rohan | Development | kubesphere-sample-dev |
Log out of the console and log back in as
project-regular
. On the DevOps Projects page, click the DevOps projectmulticluster-demo
.
Step 6: Create a pipeline
Go to the Pipelines page and click Create. In the displayed dialog box, enter
build-and-deploy-application
for Name and click Next.On the Advanced Settings tab, click Create to use the default settings.
The pipeline created is displayed in the list. Click its name to go to the details page.
Click Edit Jenkinsfile and copy and paste the following contents. Make sure you replace the value of
DOCKERHUB_NAMESPACE
with your own value, and then click OK.Note
The flag
-o
in themvn
commands indicates that the offline mode is enabled. If you have relevant maven dependencies and caches ready locally, you can keep the offline mode on to save time.After the pipeline is created, you can view its stages and steps on the graphical editing panel as well.
Click Run to run the pipeline. The pipeline will pause when it reaches the stage deploy to staging as resources have been deployed to the cluster for development. You need to manually click Proceed twice to deploy resources to the testing cluster
host
and the production cluster .After a while, you can see the pipeline status shown as Successful.
Check the pipeline running logs by clicking View Logs in the upper-right corner. For each stage, you click it to inspect logs, which can be downloaded to your local machine for further analysis.
Go to the Projects page, and you can view the resources deployed in different projects across the clusters by selecting a specific cluster from the drop-down list.