This article is by Wang Wei, 161a49da553001 CODING Nocalhost R&D leader, at the Tencent Cloud CIF Engineering Efficiency Summit. At the end of the article, you can go to the official website of the summit to watch the replay and download the PPT.
Hello everyone, and welcome to the CIF conference. What I will share with you today is: Breaking the Dilemma of Kubernetes Application Development. Let me first introduce myself briefly. I am Wang Wei from Tencent Cloud CODING DevOps. I am currently the head of Nocalhost project research and development and also a CNCF ambassador. Not much to say, let's get to the topic.
This sharing is mainly divided into five aspects:
- The first is the development dilemma in the K8s environment;
- And mainstream cloud-native development methods;
- Next is the realization of the principle of container application and hot loading;
- Development and debugging demonstration, here will use a Demo to demonstrate;
- Finally, open source co-construction and outlook.
First is the first part: the development dilemma in the K8s environment. When it comes to cloud native development, we have to start with Docker. When we have more and more microservices and the operating environment becomes more and more complex, Docker mirroring provides us with a good solution. But when there are more and more images and containers, service orchestration becomes a problem . At this time, many solutions have also appeared, such as K8s, Docker Swarm, and so on. Of course, K8s has almost become the de facto standard and the preferred solution for container orchestration. However, the capabilities provided by this de facto standard are for operation and maintenance. For example, we can define the automatic recovery mechanism of the service through Liveness and Readiness, and define the resource usage through Resource. actually add a great extra burden to developers, and also create a dilemma between development and debugging.
In addition, the cloud native technology stack span is very large, which puts forward higher requirements for developers, which also requires the team to design the cloud native architecture more in line with the needs of the business. So overall, has higher recruitment and employment costs for enterprises.
The picture below is a panorama of CNCF cloud-native application development. We will find that cloud-native development tools are still missing. Cloud native development is so difficult, so what is the mainstream development method? Or how do we solve the problem now?
After summarizing, there are currently four main cloud-native development methods as follows.
- Full manual process . For example, manually build and push the image, modify the image version, and wait for the schedule to take effect. We call each viewing of the coding effect a feedback loop of coding. The feedback loop of coding in this way of development takes about ten minutes, which is a very long process.
- Fully automatic process , that is, the manual link becomes automatic. This method is obviously faster, but its feedback loop is only shortened to about once every five minutes.
- The third is a solution that teams who have a good understanding of cloud native will often use, that is, use Telepresence as a tool for development. Telepresence is mainly to open up local and cluster networks, enabling developers to develop . This development method reduces the coding feedback loop to once every 10 seconds, but because the development service runs locally as source code, this method has certain limitations, which I will explain in depth later.
- The fourth is to use directly in the container. This way can get rid of Telepresence's usage restrictions in certain scenarios.
Next, let's talk in detail about the restrictions on the use of the network connection solution represented by Telepresence. First of all, its biggest limitation is that the local environment and the operating environment of the workload are very different, which makes it difficult for business source code to run locally. For example, the business declares the mounting of configmap, secret, volume, etc. in the K8s Manifest, which are difficult to rebuild locally. Secondly, there are environmental differences, and cross-platform, such as these platform differences between Linux and Windows, and network restrictions in some scenarios.
said so much, I believe everyone can understand that the biggest problem of 161a49da55340c developed in the K8s environment is that the mirror image needs to be rebuilt every time the code is viewed, which leads to a long and invalid wait for . Is there a solution that does not require rebuilding the image? The answer is yes. If we can implement hot reloading of processes or applications in the container, which can take effect in real time after each encoding, don't we need to rebuild the image?
Next, we continue to discuss the realization principle and scheme of this way. Let's start with the Dockerfile. The startup command of the container is defined in the Dockerfile. Generally speaking, this is the startup method of the business process. For example, to run an executable file, if we enter the container to execute the PS command, we will find that this process corresponds to the container, that is, the process with PID=1. Let’s take the Go application as an example. If we replace the process with PID=1 to run in source code, go run main.go, can we implement hot reloading of the application, and only need to re-run after modifying the code Can you see the code effect with this command?
Our thinking is not wrong, but if we want to realize this plan, we still need three conditions. The first is where does the source code of the container come from? Except for scripting languages, general business containers do not have source code; the second is to take Go applications as an example. Where does the compiled environment come from? We know that business containers built under normal circumstances will maintain the smallest runnable environment due to storage size considerations; third, if the process with PID=1 is replaced, how to prevent the container from crashing?
Let's look at how to solve these problems separately. First of all, the first point of the source code problem, we can synchronize from the local to the container to solve; the second is the compilation environment, we can replace the running business image with a development image with a compilation environment to provide a compilation environment; third , We can replace the process with PID=1 with a blocked process, and these three problems are solved. When we implement these solutions, the container actually has the basis for hot reloading. 161a49da55347e is based on the above solutions to achieve . Next, I will use a Demo to demonstrate the application's hot reload and one-key Debug effect.
Nocalhost provides the VSCode plug-in and JetBrains' full range of plug-ins, which can be used immediately as long as they are installed. Next, I will use Golang as an example to demonstrate the development of the Demo project Booking for.
[Please click 161a49da5534bb at the end of the read the original , and go to the CIF Summit "Open Source Ecology and Performance Improvement" special -161a49da5534bd "Cracking the Dilemma of Kubernetes Application Development" , watch the demo 08:00
This is the end of the demonstration of real-time hot loading of container applications and one-click debugging. Interested students can follow the Quick Start guide on the official website of Nocalhost (nocalhost.dev) to give it a try.
Through the demonstration, I believe that everyone has understood the new cloud-native development experience brought by Nocalhost. In the last part, I will share with you open source co-construction and prospects. Nocalhost is currently a completely open source project. The code is hosted on GitHub. It has 900+ stars. It is also a CNCF Landscape project and is included in the cloud native panorama. Everyone is welcome to pay attention and contribute.
Regarding the outlook, in this sharing, I introduced the two development methods of Telepresence and Nocalhost. They actually have different ideas for solving problems. You can choose one method to use according to your business situation. In addition, Nocalhost provides a complete development environment and development process management capabilities. For teams who want to manage the development environment in a unified manner, you can install Nocalhost Server to centrally manage development clusters, applications, and development environments. Of course, Server is also open source and free. Here are a few screenshots of Server, and interested students can follow the official documents to install and use.
My sharing is over here. Welcome to the official website of Nocalhost (nocalhost.dev) and install and try it according to the official documentation. Thank you.
Click here to watch the CIF summit replay
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。