After initializing Kubernetes master, we need to expose insecure port 8080 for edgecontroller/kubectl to work with http connection to Kubernetes apiserver. Please follow below steps to enable http port in Kubernetes apiserver.
vi /etc/kubernetes/manifests/kube-apiserver.yaml # Add the following flags in spec: containers: -command section - --insecure-port=8080 - --insecure-bind-address=0.0.0.0
(Optional)KubeEdge also supports https connection to Kubernetes apiserver. Follow the steps in Kubernetes Documentation to create the kubeconfig file.
Enter the path to kubeconfig file in controller.yaml
controller: kube: ... kubeconfig: "path_to_kubeconfig_file" #Enter path to kubeconfig file to enable https connection to k8s apiserver
git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge cd $GOPATH/src/github.com/kubeedge/kubeedge
Configuring MQTT mode¶
The Edge part of KubeEdge uses MQTT for communication between deviceTwin and devices. KubeEdge supports 3 MQTT modes:
- internalMqttMode: internal mqtt broker is enabled.
- bothMqttMode: internal as well as external broker are enabled.
- externalMqttMode: only external broker is enabled.
Use mode field in edge.yaml to select the desired mode.
RootCA certificate and a cert/key pair is required to have a setup for KubeEdge. Same cert/key pair can be used in both cloud and edge.
# $GOPATH/src/github.com/kubeedge/kubeedge/build/tools/certgen.sh genCertAndKey edge
The cert/key will be generated in the
Run as a binary¶
Firstly, make sure gcc is already installed on your host. You can verify it via:
Build Cloud and edge
cd $GOPATH/src/github.com/kubeedge/kubeedge make
cd $GOPATH/src/github.com/kubeedge/kubeedge make all WHAT=cloud
The path to the generated certificates should be updated in
$GOPATH/src/github.com/kubeedge/kubeedge/cloud/conf/controller.yaml. Please update the correct paths for the following :
Create device model and device CRDs.
cd $GOPATH/src/github.com/kubeedge/kubeedge/build/crds/devices kubectl create -f devices_v1alpha1_devicemodel.yaml kubectl create -f devices_v1alpha1_device.yaml
cd $GOPATH/src/github.com/kubeedge/kubeedge/cloud # run edge controller # `conf/` should be in the same directory as the cloned KubeEdge repository # verify the configurations before running cloud(edgecontroller) ./edgecontroller
Deploy the Edge node¶
We have provided a sample node.json to add a node in kubernetes. Please make sure edge-node is added in kubernetes. Run below steps to add edge-node.
$GOPATH/src/github.com/kubeedge/kubeedge/build/node.jsonfile and change
metadata.nameto the name of the edge node
kubectl apply -f $GOPATH/src/github.com/kubeedge/kubeedge/build/node.json
Transfer the certificate file to the edge node
Run as a binary¶
cd $GOPATH/src/github.com/kubeedge/kubeedge make all WHAT=edge
KubeEdge can also be cross compiled to run on ARM based processors. Please follow the instructions given below or click Cross Compilation for detailed instructions.
cd $GOPATH/src/github.com/kubeedge/kubeedge/edge make edge_cross_build
KubeEdge can also be compiled with a small binary size. Please follow the below steps to build a binary of lesser size:
apt-get install upx-ucl cd $GOPATH/src/github.com/kubeedge/kubeedge/edge make edge_small_build
Note: If you are using the smaller version of the binary, it is compressed using upx, therefore the possible side effects of using upx compressed binaries like more RAM usage, lower performance, whole code of program being loaded instead of it being on-demand, not allowing sharing of memory which may cause the code to be loaded to memory more than once etc. are applicable here as well.
edgehub.websocket.keyfilewith your own certificate path
- Update the IP address of the master in the
fb4ebb70-2783-42b8-b3ef-63e2fd6d242eq with edge node name in edge.yaml for the below fields :
# run mosquitto mosquitto -d -p 1883 # or run emqx edge # emqx start # run edge_core # `conf/` should be in the same directory as the cloned KubeEdge repository # verify the configurations before running edge(edge_core) ./edge_core # or nohup ./edge_core > edge_core.log 2>&1 &
Note: Please run edge using the users who have root permission.
After the Cloud and Edge parts have started, you can use below command to check the edge node status.
kubectl get nodes
Please make sure the status of edge node you created is ready.
If you are using HuaweiCloud IEF, then the edge node you created should be running (check it in the IEF console page).
Try out a sample application deployment by following below steps.
kubectl apply -f $GOPATH/src/github.com/kubeedge/kubeedge/build/deployment.yaml
Note: Currently, for edge node, we must use hostPort in the Pod container spec so that the pod comes up normally, or the pod will be always in ContainerCreating status. The hostPort must be equal to containerPort and can not be 0.
Then you can use below command to check if the application is normally running.
kubectl get pods
Run Edge Unit Tests¶
To run unit tests of a package individually.
export GOARCHAIUS_CONFIG_PATH=$GOPATH/src/github.com/kubeedge/kubeedge/edge cd <path to package to be tested> go test -v
Run Edge Integration Tests¶