Yin Ding


[KubeEdge](https://kubeedge.io/en/) is an open source framework for edge computing built on Kubernetes that is an incubation-level [CNCF](https://www.cncf.io/projects/kubeedge/) project. KubeEdge helps developers deploy and manage containerized applications in the cloud and on the edge using the same unified platform. KubeEdge handles networking, deployment and data synchronization between edge and cloud infrastructure.



KubeEdge cloud components

KubeEdge cloud components all fall under what is called “CloudCore” which handles communication between the Kubernetes cluster via API and then communicates with the edge devices.

KubeEdge edge components

KubeEdge edge components fall under “EdgeCore” and handle communication between application containers, devices, and the cloud.


Code Architecture Overview

KubeEdge has many modules, users can choose to turn on or off some modules according to their needs. These modules are managed through beehive. Beehive is the core message communication framework in KubeEdge, which is used for registration of different modules and communication between modules. Both CloudCore and EdgeCore components in KubeEdge depend on the beehive framework.

The module definition is an interface. As long as this interface is implemented, it can become a module. Common modules in KubeEdge, such as cloudhub, edgehub, edgeController, etc., have already implemented this interface.

// Module interface
type Module interface {
   Name() string
   Group() string
   Start()
   Enable() bool
}


The Register function of each module calls the Register function of beehive to register the module in beehive. According to whether the module is enabled (modules.enabled) in the configuration file, beehive adds the module to the internal modules map or disabledModules map for management.

	cloudhub.Register(c.Modules.CloudHub)
	edgecontroller.Register(c.Modules.EdgeController)
	devicecontroller.Register(c.Modules.DeviceController)
	nodeupgradejobcontroller.Register(c.Modules.NodeUpgradeJobController)
	synccontroller.Register(c.Modules.SyncController)
	cloudstream.Register(c.Modules.CloudStream, c.CommonConfig)
	router.Register(c.Modules.Router)
	dynamiccontroller.Register(c.Modules.DynamicController)

Beehive uses the golang channel to realize inter-module communication. The communication methods include "unicast" and "multicast", that is, the message can be sent to a certain module alone, or the message can be sent to the module group (that is, the edged, hub, bus and other groups mentioned above). Beehive uses context to manage communication between groups and modules. When using channel as the communication method, ChannelContext implements two interfaces related to context: ModuleContext and MessageContext.

// ModuleContext is interface for context module management
type ModuleContext interface {
	AddModule(info *common.ModuleInfo)
	AddModuleGroup(module, group string)
	Cleanup(module string)
}


// MessageContext is interface for message syncing
type MessageContext interface {
	// async mode
	Send(module string, message model.Message)
	Receive(module string) (model.Message, error)
	// sync mode
	SendSync(module string, message model.Message, timeout time.Duration) (model.Message, error)
	SendResp(message model.Message)
	// group broadcast
	SendToGroup(group string, message model.Message)
	SendToGroupSync(group string, message model.Message, timeout time.Duration) error
}