Use GitOps to Achieve Continuous Deployment of Applications
In KubeSphere 3.4, we introduce the GitOps concept, which is a way of implementing continuous deployment for cloud-native applications. The core component of GitOps is a Git repository that always stores applications and declarative description of the infrastructure for version control. With GitOps and Kubernetes, you can enable CI/CD pipelines to apply changes to any cluster, which ensures consistency in cross-cloud deployment scenarios.
This section walks you through the process of deploying an application using a continuous deployment.
Prerequisites
You have a workspace, a DevOps project and a user (project-regular) invited to the DevOps project with the operator role. If they are not ready yet, please refer to Create Workspaces, Projects, Users and Roles.
You need to enable the KubeSphere DevOps system.
Import a Code Repository
Log in to the KubeSphere console as project-regular. In the left-side navigation pane, click DevOps Projects.
On the DevOps Projects page, click the DevOps project you created.
In the left-side navigation pane, click Code Repositories.
On the Code Repositories page on the left, click Import.
In the Import Code Repository dialog box, enter the name of code repository, for example, open-podcasts, and select a code repository. Optionally, you can set an alias and add description.
In the Select Code Repository dialog box, click Git. In Code Repository URL, enter the URL of the code repository, for example, https://github.com/kubesphere-sigs/open-podcasts, and click OK.
Note
As the imported code repository is a public repository, it is not necessary to create a credential. However, if you add a private repository, a credential is required. For more information about how to create a credential, please refer to Credential Management.
Create a Continuous Deployment
In the left-side navigation pane, click Continuous Deployments.
On the Continuous Deployments page, click Create.
On the Basic Information tab, enter a name of the continuous deployment, for example, open-podcasts, and choose a code repository. Then, click Next. Optionally, you can set an alias and add description.
In the Deployment Location section of the Deployment Settings tab, configure the cluster and project for which the continuous deployment will be deployed.
In the Code Repository Settings section, specify a branch or tag of the repository and the manifest file path.
Parameter Description Revision
The commit ID, branch, or tag of the repository. For example, master, v1.2.0, 0a1b2c3, or HEAD.
Manifest File Path
The manifest file path. For example, config/default.
In the Sync Strategy section, select Auto Sync or Manual Sync as needed.
Auto Sync: automatically syncs an application when it detects differences between the desired manifests in Git, and the live state in the cluster. The following table describes the parameters.
Parameter Description Prune resources
If checked, it will delete resources that are no longer defined in Git. By default and as a safety mechanism, auto sync will not delete resources.
Self-heal
If checked, it will force the state defined in Git into the cluster when a deviation in the cluster is detected. By default, changes that are made to the live cluster will not trigger auto sync.
Manual Sync: manually triggers application synchronization according to the synchronization options set. The following table describes the parameters.
Parameter Description Prune resources
If checked, it will delete resources that are no longer defined in Git. By default and as a safety mechanism, manual sync will not delete resources, but mark the resource out-of-sync state.
Dry run
Preview apply without affecting the cluster.
Apply only
If checked, it will skip pre/post sync hooks and just run kubectl apply for application resources.
Force
If checked, it will use kubectl apply —force to sync resources.
Note
To configure the preceding parameters, go to the list or details page of continous deployment, select Sync from the drop-down list, and then specify parameter values in the Sync Resource dialog box.
In the Sync Settings section, configure parameters as needed.
Parameter Description Skip schema validation
Disables kubectl validation. —validate=false is added when kubectl apply runs.
Auto create project
Automatically creates projects for application resources if the projects do not exist.
Prune last
Resource pruning happened as a final, implicit wave of a sync operation, after other resources have been deployed and become healthy.
Selective sync
Syncs only out-of-sync resources.
In the Prune Propagation Policy section, select a policy as needed.
Parameter Description foreground
Deletes dependent resources first, and then deletes the owner resource.
background
Deletes the owner resource immediately, and then deletes the dependent resources in the background.
orphan
Deletes the dependent resources that remain orphaned after the owner resource is deleted.
In the Replace Resource section, specify whether to replace the resources that already exist.
If checked, the resources will be synced by kubectl replace/create. By default, the resources will be synced by kubectl apply.
Click Create. The resource you create will appear in the list of continuous deployments.
View the Created Continuous Deployment
On the Continuous Deployments page, view the created continuous deployment. The following table describes the parameters.
Item Description Name Name of the continuous deployment. Health Status Health status of the continuous deployment, which includes the following: - Healthy: Resources are healthy.
- Degraded: Resources are degraded.
- Progressing: Resources are being synchronized. This is the default state.
- Suspended: Resources have been suspended and are waiting to be resumed.
- Unknown: The resource state is unknown.
- Missing: Resources are missing.
Sync Status Synchronization status of the continuous deployment, which includes the following: - Synced: Resources have been synchronized.
- Out of sync: The actual running state of resources is not as desired.
- Unknown: The resource synchronization state is unknown.
Deployment Location Cluster and project where resources are deployed. Update Time Time when resources are updated. Click on the right of the continuous deployment, and you can perform the following:
- Edit Information: edits the alias and description.
- Edit YAML: edits the YAML file.
- Sync: triggers resources synchronization.
- Delete: deletes the continuous deployment.
Warning
Deleting a continuous deployment also deletes resources associated with the continuous deployment. Therefore, exert caution when deleting the continuous deployment.
- Click the created continuous deployment to go to its details page, where you can view the synchronization status and result.
Access the Created Application
Go to the project where the continuous deployment resides, in the left-side navigation pane, click Services.
On the Services page on the left, click on the right of the deployed application, and click Edit External Access.
In Access Mode, select NodePort, and click OK.
In the External Access column, check the exposed port, and access the application by nodeIP: nodePort.
Note
Before accessing the service, open the exposed port in security groups.
Feedback
Was this page Helpful?
Yes No