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

Import a Code Repository

  1. Log in to the KubeSphere console as project-regular. In the left-side navigation pane, click DevOps Projects.

  2. On the DevOps Projects page, click the DevOps project you created.

  3. In the left-side navigation pane, click Code Repositories.

  4. On the Code Repositories page on the left, click Import.

  5. 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.

  6. 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

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

  2. On the Continuous Deployments page, click Create.

  3. 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.

  4. In the Deployment Location section of the Deployment Settings tab, configure the cluster and project for which the continuous deployment will be deployed.

  5. In the Code Repository Settings section, specify a branch or tag of the repository and the manifest file path.

    ParameterDescription

    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.

  6. 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.

      ParameterDescription

      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.

      ParameterDescription

      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.

  7. In the Sync Settings section, configure parameters as needed.

    ParameterDescription

    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.

  8. In the Prune Propagation Policy section, select a policy as needed.

    ParameterDescription

    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.

  9. 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.

  10. Click Create. The resource you create will appear in the list of continuous deployments.

View the Created Continuous Deployment

  1. On the Continuous Deployments page, view the created continuous deployment. The following table describes the parameters.

    ItemDescription
    NameName of the continuous deployment.
    Health StatusHealth 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 StatusSynchronization 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 LocationCluster and project where resources are deployed.
    Update TimeTime when resources are updated.
  2. Click icon 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.

  1. Click the created continuous deployment to go to its details page, where you can view the synchronization status and result.

Access the Created Application

  1. Go to the project where the continuous deployment resides, in the left-side navigation pane, click Services.

  2. On the Services page on the left, click icon on the right of the deployed application, and click Edit External Access.

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

  4. 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