preface

At the beginning of 2020, the author joined the cloud development department of Starloop. Before that, the most complex container platform was Docker Swarm, and I didn’t know much about it. Therefore, it was essential to be familiar with K8S at the beginning of my work. However, K8S is a container platform with some complexity, so the setup of the development/learning environment can be complex. After trying to build a complete version of the cluster failed, I tried Minikube again, but I found many shortcomings of Minikube, such as limited function and low configurability. Therefore, after working for more than half a year and mastering some basic knowledge, I began to develop Mediumkube to be introduced in this paper. The original intention may be to help the partners who have just joined Star Ring to get familiar with K8S, but the feeling that the demand is not high, let it go. For myself, this has become a useful tool for quickly setting up a development environment.

Container cloud technology has infiltrated every aspect of our daily development over the years, from the development of some enterprise applications to the building of personal websites. Whether an application can run on a container platform and take advantage of the container platform’s features for performance tuning/cost management is a really hard part to ignore. Nowadays, many applications are completely developed based on the cloud platform, and they make full use of the capabilities of the cloud platform to achieve features such as micro-service, service grid, flexibility and so on. However, an application developed entirely based on the cloud platform naturally needs a complex cloud development environment. Whether it is the deployment of the application itself, the utilization of the API of the cloud platform, or even the expansion of the capabilities of the cloud platform itself, it will be of great help.

As a development environment, our concerns may be different from those of a production environment. Here are some of my personal expectations for a development environment.

  • Can be quickly deployed, deleted
  • Functional integrity
  • Whether to provide rich configuration items for advanced users
  • Developer visibility into the underlying components of the environment
  • As a developer in China, can you easily use the open source software ecosystem

There are a number of freeware applications out there that can be used as container cloud development environments, such as Minikube, the nutty K8S distribution, K3S for edge computing and resource-constrained environments, or Docker Swarm, which is one of the easiest container cloud environments to deploy for non-K8S users.

The MediumKube presented in this article differs from the more productized software mentioned above in that it provides a highly customizable solution based on libvirt and cloud-init. It is more of a virtual machine management tool than a pure Kubernetes lightweight distribution, and it provides some capabilities that make it a useful piece of software for deploying a Kubernetes development environment.


Use cloud-init to quickly initialize a virtual machine instance

Cloud-init is a common standard for IaaS Cloud services, driven by Canonical, the company that developed Ubuntu. Cloud-init is an example of Infrastructure as Code. By writing the configuration file declaratively, we can initialize the cloud instance. It is such a common standard that we can integrate it into a micro-project of hundreds of lines of code to implement a minimalist IaaS service. MediumKube uses this tool, making it a highly customizable virtual machine management tool in its own right. Of course, since it is positioned for rapid deployment of Kubernetes, it also comes with a default cloud-init template, which is distributed along with the source code itself.

The image above is part of MediumKube’s built-in template. This template does the work related to the installation of users, software sources, system configuration scripts, Docker/Kubernetes, so that once the instance is deployed, it comes with the corresponding software environment, and there is no need to do additional configuration

Configure and template engines

MediumKube supports a template engine. By writing global configuration items and using them in cloud-init templates, users can deploy highly customized virtual machine clusters.

The figure lists some of the configuration items supported by MediumKube. Some affect the properties of the virtual machine, while others can be rendered into templates. For example, the very useful HttpProxy is very practical for Chinese users. Because of the support of the template engine, users no longer need to set the configuration of the proxy in multiple scattered places over and over again. Instead, they can set the configuration of the proxy globally through a unified configuration file. While there are many configuration options, MediumKube has recommended default values for each, which strikes a balance between flexibility and ease of use. I’m sure you all have trouble with Minikube when you don’t know where to configure the advanced parameters of the virtual machine, so it’s also a great advantage for both beginners and advanced users.


Use MediumKuBed to maintain a stable network environment

A stable network environment is also important for the development environment. Early in MediumKube’s development, certain configurations, such as listening to agents on the host, were no longer available due to changes in the network environment. The host IP often changes due to DHCP or switching WiFi. To solve this problem, MediumKube maintains a virtual network for users that is easy to configure. Users only need to declare simple interface information, and MediumKube will automatically configure iptables, dnsmasq and other information.

The following diagram shows the early development topology of MediumKuBed, similar to Docker’s Bridge network, which is very simple, but also very practical. As development progresses, more and more features will be added.

MediumKuBed is registered as a module in Systemd, so the manager is very simple.


Easy to use command line tool

On the UI side, MediumKube provides an easy-to-use command-line interface. For example, users can display deployed virtual machines and manage their life cycles, such as stop/start/delete/deploy

At the same time, MediumKube also has a quick cluster build, join a cluster, reset nodes and other commands, making cluster management easy. For example, if a user needs to deploy a two-node cluster, the following simple command is required

$ mediumkube deploy node1 node2

$ mediumkube init node1

$ mediumkube join node2 node1

Of course, if users are not satisfied with these simple commands, they can also log in to the virtual machine through shell commands.

As shown in the figure above, users do not need to remember any IP addresses, and if configured properly, they do not need to manually manage any keys, so they can manage nodes directly.


The future of MediumKube

Mediumkube is a very young and niche project. It solves some people’s pain points at the same time, it also has considerable limitations. For example, cluster deployment in a stand-alone environment will result in a limited system resources, and the project will be relatively low level of productization, which will make it only “theoretically” practical. As a developer of Mediumkube, I want to make it more and more user-friendly, so here are my plans for it.

clustering

As mentioned above, MediumKube has some limitations in a standalone environment, so clustering is definitely a future plan. Of course, the simplicity of the system is compromised by the introduction of complex elements, such as MediumKube becoming as difficult to deploy as a K8S cluster, or by the addition of distributed elements which may introduce more bugs. Many of these questions are not big or big, but they do take time to think about. What is the architecture of clustered MediumKube? How is the deployment of a virtual machine scheduled? What technique does the Overlay network use (the screenshot above seems to give away the fact that I’m going to use a flannel)? How to make distributed deployment simple but flexible? What if you simply plan the nodes? Do you need graphical support? It’s a lot to think about.

Stability and code quality

As a development environment, stability may not be as demanding, but MediumKuBed did have a lot of memory usage in its early days. Also, as a toy project and Golang learning use case, MediumKube has some code quality concerns. The file transfer module code, for example, is so bad that there is a noticeable difference in the speed of the uplink and the downlink. Hopefully it will improve in the future.

Said in the last

Finally, I hope that technology can really improve the convenience of our lives. I would like to thank CNCF, Canonical, Libvirt, Google and other organizations and developers in the open source community for bringing us these fun, easy to use, free quality software. I look forward to seeing more interesting technologies in the future.


Author: Wen Yun Lu