# EdgeX over Kubernetes: Enabling Container Orchestration in EdgeX
## 3 Preliminary Research
### Kubernetes  
Kubernetes is an open-source container orchestration platform that manages and deploys container-based applications [22]. A Kubernetes cluster includes master nodes and at least one worker node. A pod is the smallest deployable unit that can be created and managed by Kubernetes. A pod can contain one or more containers that share storage and networks, it has a specification of how each container runs, and each pod is assigned a unique internal IP address. Moreover, one specification can create several pods, referred to as replicas [23], to provide scalability and availability for applications. Note that a pod is ephemeral, and it can be recreated or terminated at any time. Further, when a pod restarts, its IP address changes. To allow access to pods, Kubernetes defines _Service_ of three kinds: _ClusterIP_, _NodePort_, and _LoadBalancer_[22]. A _Service_ abstracts multiple pods as a group and exposes the group to the network. By default, a group is assigned an invariable IP address by _ClusterIP_. _ClusterIP_ Service works as a frontend for grouped pods, and grouped pods work as a backend. When the frontend (i.e., _ClusterIP_ Service) receives traffic, it redirects requests to the backend (i.e., grouped pods) following Kubernetes' rules. However, _ClusterIP_ is used only for connection between cluster components, so it cannot receive the traffic from outside. For communicating outside, the _NodePort_ and _LoadBalancer_ Services are used. The _NodePort_ Service enables access from outside of the cluster by reserving and exposing port numbers on external IP addresses of each worker node; then, traffic requests can access to backend pods using an external IP address and reserved port. The _LoadBalancer_ Service is provided by a cloud vendor such as Google Cloud Platform, Azure [5], and Amazon Web Services. The cloud vendor provides an external IP address and URL to the _LoadBalancer_ Service for access from outside. In Kubernetes, the master node oversees the management and control of the Kubernetes cluster and consists of _etcd_, _kube-scheduler_, _kube-controller-manager_, and _kube-apiserver_. The _etcd_ is backend storage that stores all cluster data in a key-value structure. The _kube-scheduler_ is in charge of assigning a newly created pod to a node according to scheduler rules, such as resources optimization, policy constraints, and node-affinity. The _kube-controller-manager_ ensures that the current node or pod operates in the desired state. For example, when using autoscaling, if resource usage is found to be above the threshold of the pod specification through periodic monitoring, the _kube-controller-manager_ determines whether to deploy a replica or scale up the pod resources according to the specifications. The _kube-apiserver_ processes all requests from the cluster and interacts with the worker node through _kubelet_. Kubernetes provides three kinds of autoscalers to provide optimal resource management on demand: Cloud Autoscaler (CA), Vertical Pod Autoscaler (VPA), and Horizontal Pod Autoscaler (HPA) [23]. The CA works with cloud services to adjust the number of nodes. If a node has insufficient resources to create a pod, the CA adds a node and creates a pod on the newly added node. The VPA configures a pod with more resources when pod resources are insufficient, but the pod must restart to apply the configuration. The HPA increases the number of pods to scale resources. Specifically, the HPA stores the resource metric of a pod in the metric server and scales by increasing the number of pods when the metric exceeds a specified threshold. Therefore, multiple replicas can provide one application service. When a user request reaches a specific application service, Kubernetes forwards the request to a pod according to the _kube-proxy_ load balancing policy, such as round robin or random approach. The Kubernetes HPA can adjust pod resources dynamically according to resource status without interruption of existing application services.