KubeSphere introduces a concept for implementing continuous deployment for cloud-native applications – GitOps. The core idea of GitOps is to have a Git repository and store the declarative infrastructure and applications of the application system in the Git repository for version control. GitOps, combined with Kubernetes, can leverage automated delivery pipelines to apply changes to any number of specified clusters, thereby solving the consistency issues of cross-cloud deployments.

This document demonstrates how to create a continuous deployment to implement application deployment.

Prerequisites

  • The DevOps extension must be installed and enabled on the KubeSphere platform.

  • A workspace, a DevOps project, and a user (e.g., project-regular) have been created, and the user has been invited to the DevOps project and granted the operator role. Please refer to Invite a User to a DevOps Project.

  • A project has been created in the workspace under Project Management > Project List.

Import a Code Repository

  1. Log in to the KubeSphere console as the project-regular user and enter your workspace.

  2. In the left navigation pane, click DevOps > Code Repositories.

  3. Select a DevOps project from the drop-down list in the upper left corner of the page.

  4. Click Create on the page.

  5. In the Import Code Repository dialog box, enter a code repository name, such as open-podcasts, and then click to select a code repository. You can also set an alias and add a description for the code repository.

  6. In the Select Code Repository dialog box, click Git. In the Repository URL field, enter the repository URL, such as https://github.com/kubesphere-sigs/open-podcasts, and click OK.

    Note

    This imports a public repository, so no credential creation is required. If you are adding a private repository, you need to create a credential. For more information on how to add credentials, please refer to Credentials.

Create a Continuous Deployment

  1. In the left navigation pane, click Continuous Deployments.

  2. On the Continuous Deployments page on the right, click Create.

  3. On the Basic Information tab, enter a name for the continuous deployment, such as open-podcasts. In the Deployment Location section, select the cluster and project for the continuous deployment. Click Next.

  4. On the Code Repository Settings tab, select the code repository created in the previous step, and set the branch or tag of the code repository and the path to the Kustomization manifest file. Click Next.

    Parameter Description

    Revision

    The commit ID, branch, or tag in the Git repository. For example, master, v1.2.0, 0a1b2c3, or HEAD.

    Manifest File Path

    Set the path to the manifest file. For example, deployments/nginx or deployments/.

  5. In the Sync Policy section, select Auto Sync or Manual Sync as needed.

    • Auto Sync: Automatically triggers application synchronization when a discrepancy is detected between the manifests in the Git repository and the live state of the deployed resources, according to the set sync options. The specific parameters are as follows.

      Parameter Description

      Prune Resources

      If checked, resources that do not exist in the Git repository will be deleted during auto-sync. If unchecked, resources in the cluster will not be deleted when auto-sync is triggered.

      Self-Heal

      If checked, when a deviation is detected between the state defined in the Git repository and the deployed resources, the definition in the Git repository will be forcibly applied. If unchecked, changes made to the deployed resources will not trigger auto-sync.

    • Manual Sync: Manually triggers application synchronization according to the set sync options.

  6. In the Sync Settings section, set the synchronization-related parameters as needed.

    Parameter Description

    Skip Schema Validation

    Skips kubectl validation. Adds the --validate=false flag when executing kubectl apply.

    Auto Create Namespace

    Automatically creates a namespace for the application resources if the namespace does not exist.

    Prune Last

    During sync operations, resources are pruned only after all other resources have been deployed and are in a healthy state.

    Selective Sync

    Only synchronizes resources in the out-of-sync state.

  7. In the Prune Propagation Policy section, select a prune propagation policy as needed.

    Parameter Description

    foreground

    Deletes dependent resources first, then deletes the owner resource.

    background

    Deletes the owner resource first, then deletes dependent resources.

    orphan

    Deletes the owner resource, leaving dependent resources as orphans.

  8. In the Replace Resource section, choose whether to replace existing resources.

    Note

    If checked, the kubectl replace/create command will be executed to synchronize resources. If unchecked, the kubectl apply command will be used to synchronize resources.

  9. Click Create. After the resource is created, it will be displayed in the continuous deployment list.

View Continuous Deployment Information

  1. View the information of the created continuous deployment in the Continuous Deployments list. The specific parameters are as follows.

    Parameter Description

    Name

    The name of the continuous deployment.

    Health Status

    The health status of the continuous deployment. Mainly includes the following statuses:

    • Healthy: The resource is healthy.

    • Degraded: The resource has been degraded.

    • Progressing: The resource is synchronizing. This status is returned by default.

    • Suspended: The resource has been suspended and is waiting to be resumed.

    • Unknown: The health status of the resource is unknown.

    • Missing: The resource is missing.

    Sync Status

    The synchronization status of the continuous deployment. Mainly includes the following statuses:

    • Synced: Resource synchronization is complete.

    • OutOfSync: The actual running state of the resource is inconsistent with the desired state.

    • Unknown: The synchronization status of the resource is unknown.

    Deployment Location

    The cluster and project where the resource is deployed.

    Update Time

    The time when the resource was updated.

  2. Click more on the right side of the continuous deployment to perform the following operations:

    • Edit Information: Edit the alias and description.

    • Edit YAML: Edit the YAML file of the continuous deployment.

    • Sync: Trigger resource synchronization.

    • Delete: Delete the continuous deployment.

    Warning

    Deleting a continuous deployment will also delete the resources associated with that continuous deployment. Please proceed with caution.

  3. Click the name of the continuous deployment to enter its details page and view the sync status and sync results.

Access the Created Application

  1. In the left navigation pane, click Application Workloads > Services. In the project drop-down list, select the project to which the continuous deployment belongs.

  2. In the Services list, find the deployed application, click more on the right, and select Edit External Access.

  3. In Access Mode, select NodePort and click OK.

  4. On the service list page, check the exposed port in the External Access column and access the application via {Node IP}:{NodePort}.

    Note

    Before accessing the service, ensure that the port in the security group is open.