One-stop DevOps in containerized scenarios enables continuous integration and continuous deployment. It significantly improves the efficiency of creating and delivering business applications. This topic uses the deployment process of a Python container application to describe how to implement containerized DevOps within the Volcano Engine ecosystem.
Scenario introduction
Deliver a Python application as a container image and deploy it to a Kubernetes cluster. When the code changes, the application deployment is automatically triggered.
Related products
- CP: Code Pipeline (CP) provides a developer-friendly, cloud-native application delivery platform and flexible, easy-to-use one-stop pipelines. It connects all stages of development and O&M, enabling high-quality and efficient continuous integration, continuous verification, and continuous release. For product details, see CP.
- CR: Volcano Engine Container Registry (CR) provides secure and highly available hosting for OCI-compliant cloud-native artifacts. These artifacts include container images and Helm charts. It helps enterprise users manage the entire lifecycle of container images and Helm charts. For product details, see CR.
- VKE: Volcengine Kubernetes Engine (VKE) deeply integrates next-generation cloud-native technologies. It provides high-performance Kubernetes cluster management services centered on containers, helping users quickly build containerized applications. For product details, see VKE.
Procedure
Step 1: Obtain the HTTPS URL and token of the code repository
To store source code in a code repository and implement DevOps with CP, first prepare the source code in a code repository. This topic uses a Gitee repository as an example.
tip
CP supports source code hosted on Gitee, GitLab, GitHub, Codeup, Gerrit, and other code repositories. It also allows you to manually enter code as the code source.
- Create a repository on Gitee.
- On the page for creating a repository, enter the repository name and path. Then, click Create. In this example, both the repository name and path are projects-zhangsan2022.
- Click Initialize readme file to create the project's Readme file.
- Click File > Create file to create a code file.
- Create a Python file named app.py. Then, click Commit at the bottom of the page. The sample code is as follows.
- Obtain the HTTPS URL of the code repository.
- Go to Settings > Private Token > Create Personal Token to create and obtain a private token.
warning
You must select user_info, projects, and hook.
Step 2: Obtain the OCI artifact repository address
The final artifacts produced by CP pipelines are OCI-compliant container images. These images must be stored in an OCI artifact repository in CR. CR provides full lifecycle management for native OCI artifact repositories.
- Obtain the network address of the OCI artifact repository.
Step 3: Create a container cluster for deployment resources
After the image is built, you must create a deployment environment, that is, a VKE cluster, to deploy applications in the pipeline.
- Select Cluster management > Addons and install the cr-credential-controller add-on.
tip
OCI artifacts in CR can be set to private or public. When an OCI artifact repository is private, pulling images requires authentication. The cr-credential-controller add-on automatically configures authentication information for pulling images from the corresponding CR instance, enabling secret-free pulls of private images.
Step 4: Create a CP pipeline
tip
On the CP code source configuration page, enter the HTTPS URL and token of the code repository obtained from Gitee.
- Create the Python–build and push image to CR pipeline. For more information, see Create a pipelines.
- Configure the input source and select the created code source. For more information, see Create a code source.
tip
In Webhook settings, enable the Code Commit event trigger. After changes are committed to the Gitee repository, the pipeline runs automatically.
- Edit the tasks. In the Build and push image to CR section, fill in the Image tag and dockerfile parameters as described below. For other settings, keep the defaults or select the resources created in the previous steps.
- dockerfile: Select "Custom file". The sample code is as follows.
- Deployment resource: Set the created cluster as the deployment resource. For information about how to create a deployment resource, see Integrate VKE cluster.
- YAML file: Select Custom file. The sample code is as follows. Replace cr-zhangsan2022-cn-beijing.cr.volces.com/namespace-zhangsan2022/oci-zhangsan2022:v1 with {OCI artifact repository address}:v1.
- Click Save to complete pipeline creation.
Step 5: Deploy the application
After the pipeline run completes, the application is deployed.
- On the pipeline page, click Run.
- Select master as the target branch.
- After the run completes, the application is deployed.
Results
After the application is deployed, you can access it through a public address.
- On the Service page of the VKE cluster, view the public address of the deployed service.
- Enter the public address in a browser to access the application.
Step 6: Continuous release
In this example, the Code Commit event trigger is enabled in the Webhook settings of the code source. After you update code in the Gitee repository, the pipeline runs automatically and deploys the updated application.
- Update the code in the Gitee repository.
- The pipeline runs automatically and deploys the updated application. Refresh the browser to view the updated application.
Related documentation
For more container DevOps content, see the Best practices section in the CP documentation.