Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate VSTS and Kubernetes for CI/CD

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to integrate VSTS and Kubernetes for CI/CD". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the integration of VSTS and Kubernetes for CI/CD".

Why does VSTS go with Kubernetes?

Usually when we develop and manage software projects, we will encounter a headache, that is, the development, testing, production environment is inconsistent, resulting in developers and testers and even quarrels with operators.

Because in common physical environments and even cloud environments, these deployment environments are prepared in advance by operation and maintenance personnel. Every time you update the code version, you have to be very careful to modify different parameter configurations before several environments, accidentally connect the database of the production environment to the test library, or write the address of the log file to a non-existent disk letter, and so on. With a micro-service orchestration framework like Kubernetes, we can describe the architecture of services and the dependencies between services in the form of code. You did it, Infrastructure As Code. This can greatly reduce the additional cost of environment switching between development, operation and maintenance.

Integrating VSTS's continuous integration capabilities and continuous release capabilities with Kubernetes makes it easier for project teams to identify and improve code problems (at this time, Infrastructure is already code), and really focus on improving the user experience and product quality.

Prepare the VSTS management environment

First of all, we need to apply for a VSTS account under www.visualstudio.com, and then create a project under the account that uses Git as code management.

After we have created the project, we can use git clone to synchronize the code base to the local development server to build the developer's workspace

Prepare the Docker Registry and Kubernetes environment

two。 Prepare a private Docker Registry. Because we need to put the good Build code on a Docker Images and push it to a private Registry. Azure Container Registry is undoubtedly a very good choice, because in a moment our code needs to be deployed to Azure's Kubernetes cluster, and the closer the Image is to the deployment, the faster the deployment will of course. And Azure Container Registry also supports global synchronization, so if your code is going to be distributed on multiple sites around the world, Azure Container Registry services are definitely the best choice. To create an Azure Docker Registry, please refer to the official document: https://docs.microsoft.com/zh-cn/azure/container-registry/

3. Prepare Kubernetes cluster. AKS service is provided on Azure, which allows us to quickly build a Kubernetes cluster environment, reducing the pressure on operators to manage the cluster. Refer to the official document: https://docs.microsoft.com/zh-cn/azure/aks/kubernetes-walkthrough-portal

Pay attention to several places in the process of building

1. Prepare the Service Principle service principal APP

two。 Prepare the Key for linux ssh login

After installing the cluster, use the Azure CLI 2.0 command: az aks install-cli so that we can automatically install Kubernetes's kubectl command line tool on your linux.

To manage Kubernetes, you need to run the following command to generate management configuration information for K8S locally

Az aks get-credentials-resource-group=myResourceGroup-name=myK8sCluster

The obtained configuration content will be placed in the / home//.kube/config file, which is very important. VSTS needs this information to link with the K8S cluster later.

We can look at the status of the cluster through the kubectl get nodes command

Start configuring the automated build and release of VSTS

We find the Build and Release menu item in the VSTS project site and click the New button.

Select a template for NodeJS with Gulp

After the creation, we first cut out the Task that is not needed for the time being, and then add the Task of Docker build Image and push Image

->

Configure Build an image Task:

Here we can use the Azure Container Registry environment that was prepared at the beginning.

Configure Push an image Task,Image Name to use BuildId as the mirrored Tag so that when you deploy to Kubernetes later, you can specify this Tag to update the Image.

The definition of Build is not too complicated. After the definition, we can directly trigger a Build to verify whether the configuration is successful.

The following figure is the log after the success of Build. In my picture, we can see that the Docker push command has added image push to the Azure registration Repository we established earlier.

After the automated build is successful, we can do automated deployment.

Create a new publication definition

Click on the blue font section in Environment to edit the deployment task

When configuring deployment tasks, select the task type for Deploy to Kubernetes, and configure the link information for Kubernetes at the blue link of Manage.

Use the set command in the Kubernetes command to notify Kubernetes to update the deployment version by setting the update address of the image.

The format of the command is: kubectl set image deployment/ =

In VSTS, you only need to fill in the back part of the argument.

Configure Service Endpoints information for Kubernetes:

After configuring the deployment task, we can try to manually deploy the previously successful Build to the Kubernetes environment

At this point, we have successfully deployed a piece of code to Kubernetes.

After the deployment is successful, you can use the kubectl get pods-w command to monitor the process of updating and replacing the container by Kubernetes. From the following figure, you can see that Kubernetes created a new pod, and then Terminate the old version of pod.

If we need to automatically link Release to Build, we can edit the Release definition, select the lightning button on the figure, and set the button of Continuous deployment trigger to Enabled.

Thank you for your reading, the above is "how to use VSTS and Kubernetes integration for CI/CD" content, after the study of this article, I believe you on how to use VSTS and Kubernetes integration for CI/CD this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report