This article is shared by CODING Nocalhost R&D director Wei Wang at Tencent Cloud CIF Project Efficiency Summit. At the end of this article, you can visit the official website of the Summit to watch the replay and download the PPT.

Hello everyone, welcome to CIF Conference, today I share with you the content is: crack Kubernetes application development dilemma. First of all, I would like to introduce myself briefly. I am Wang Wei from Tencent Cloud CODING DevOps. I am currently the r&d leader of Nocalhost project and ALSO the CNCF ambassador. Without further ado, let’s get down to business.

This sharing is mainly divided into five aspects:

  1. Firstly, the development dilemma in THE K8s environment;
  2. And mainstream cloud native development;
  3. Next is the principle of implementing container application and hot loading;
  4. Develop and debug the Demo, which will be demonstrated by a Demo;
  5. Finally, open source construction and prospects.

First, 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 more and more complex operating environment, Docker image provides a good solution for us. But as the number of mirrors and containers grows, orchestration of services becomes a challenge. At this time, many schemes emerged, such as K8s, Docker Swarm and so on. Of course K8s has almost become the de facto standard and the preferred solution for container choreography, but the capabilities provided by the de facto standard are operational oriented. For example, Liveness and Readiness can be used to define automatic recovery mechanisms for services and Resource usage. These definitions put a huge extra burden on developers and create development and debugging dilemmas.

In addition, the technology stack span of cloud originators 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 business. So overall, it’s more expensive for companies to hire and employ people.

The picture below is a panorama of CNCF cloud native application development. We can find that the part of cloud native development tools is still missing at present. As hard as cloud native development is, what’s the mainstream approach? Or what are we doing now?

After summary, there are four main cloud native development modes at present.

  1. All manual process. For example, manually build and push the image, modify the image version, and wait for the scheduling to take effect. We call it the coding feedback loop every time we look at the coding, and this way the coding feedback loop takes about ten minutes, which is a very long process.
  2. Automatic processes, that is, manual processes become automatic. This is obviously faster, but the feedback loop is only shortened to five minutes or so.
  3. The third option is one that teams that are familiar with cloud native often use, which is Telepresence. Telepresence connects local and cluster networks so that developers can develop locally. This approach reduces the coding feedback loop to one in 10 seconds, but because the development service runs locally in source code, there are limitations to this approach, which I’ll cover in more detail later.
  4. The fourth is to use Nocalhost and develop directly in the container. This way you can get rid of the limitations of Telepresence in certain scenarios.

Let’s talk more about the limitations of Telepresence. First, the biggest limitation is that the local environment and the workload run in a very different environment, which makes it difficult to run business source code locally. For example, the K8s Manifest declares configmap, Secret, volume mounts, etc., which are difficult to recreate locally. Then there are environmental differences, cross-platform differences like those between Linux and Windows, and network limitations in some scenarios.

Having said that, I believe you can understand that the biggest problem with development in the K8s environment is that every time the code is viewed, the image needs to be rebuilt, which leads to long and ineffective waits. Is there a solution that doesn’t require a mirror rebuild? The answer is yes. If we could implement hot loading of processes or applications in containers that would work in real time after each code, wouldn’t we need to rebuild the image?

Next, we continue to discuss the implementation principle and scheme of this approach. Let’s start with Dockerfile. The container startup command is defined in Dockerfile. Generally, this is how business processes are started. For example, if we run an executable file, if we enter the container and execute the PS command, we will find that this process corresponds to the process in the container, that is, PID = 1. Take the Go application as an example. If the PID = 1 process is replaced by the source code, Go run main. Go, can we achieve hot loading of the application, and modify the code only need to run the command again, you can see the code effect?

We’re on the right track, but if we want to implement this solution, we need three more things. The first is where does the source code for the container come from? With the exception of scripting languages, there is no source code for most business containers; Second, take the Go application as an example, where does the compilation environment come from? We know that business containers are typically built to keep a minimum runnable environment due to storage size considerations; If the PID = 1 process is replaced, how to prevent the container Crash?

Let’s look at how to solve each of these problems. First of all, the source code problem can be solved from local synchronization to the container. The second is the compilation environment. We can replace the running business image with the development image with the compilation environment to provide the compilation environment. Third, we can replace the PID = 1 process with a blocking process, and these three problems are solved. When we implement these solutions, the container actually has the basis of hot loading, Nocalhost principle is based on the above solution. Next I will use a Demo to demonstrate the effects of hot loading and one-click Debug.

Nocalhost provides the full range of VSCode plug-ins and JetBrains plug-ins that are immediately available upon installation. Next, I will take Golang as an example to demonstrate the development of Demo project Booking for.

[Please click the end of the article to read the original text, go to CIF Summit “Open Source Ecology and Efficiency Improvement” special session – “Cracking Kubernetes Application Development Dilemma”, watch the Demo at 08:00.]

This concludes the real-time hot loading and one-click debugging of the container application. If you are interested, you can follow the Quick Start guide on Nocalhost (nocalhost.dev) to give it a try.

With the demo, I believe you understand the new cloud-native development experience brought by Nocalhost. In the last part, I will share with you the prospect of open source construction. Nocalhost is currently a completely open source project, with the code hosted on GitHub. It already has 900+ STAR, which is also a CNCF Landscape project, and is included in the cloud native panorama. You are welcome to pay attention and contribute.

In this post, I introduce Telepresence and Nocalhost. They have different approaches to solving problems. You can choose one of them according to your business situation. In addition, Nocalhost provides complete development environment and development process management capabilities. For teams who want to manage the development environment uniformly, they can install Nocalhost Server to centrally manage the development cluster, application, and development environment. Of course, The Server is also open source and free. I provide a few screenshots of the Server for those interested to follow the official documentation to install and use.

And that’s the end of my sharing. Welcome to Nocalhost (nocalhost.dev) official website, and follow the official documentation to install and try it out.

Click here for a replay of CIF Summit