Setup KubeEdge from sourcecode

Abstract

KubeEdge is composed of cloud and edge parts. It is built upon Kubernetes and provides core infrastructure support for networking, application deployment and metadata synchronization between cloud and edge. So if we want to setup kubeedge, we need to setup kubernetes cluster, cloud side and edge side.

  • on cloud side, we need to install docker, kubernetes cluster and cloudcore.
  • on edge side, we need to install docker, mqtt and edgecore.

Prerequisites

you can also run other runtime, such as containerd

Run KubeEdge

Setup cloud side

Clone KubeEdge

  1. git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge
  2. cd $GOPATH/src/github.com/kubeedge/kubeedge

Generate Certificates

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.

  1. $GOPATH/src/github.com/kubeedge/kubeedge/build/tools/certgen.sh genCertAndKey edge

The cert/key will be generated in the /etc/kubeedge/ca and /etc/kubeedge/certs respectively, so this command should be run with root or users who have access to those directories. We need to copy these files to the corresponding edge side server directory.

Run as a binary

  • Firstly, make sure gcc is already installed on your host. You can verify it via:
  1. gcc --version
  • Build cloudcore
  1. cd $GOPATH/src/github.com/kubeedge/kubeedge/
  2. make all WHAT=cloudcore
  • Create device model and device CRDs.
  1. cd $GOPATH/src/github.com/kubeedge/kubeedge/build/crds/devices
  2. kubectl create -f devices_v1alpha1_devicemodel.yaml
  3. kubectl create -f devices_v1alpha1_device.yaml
  • Copy cloudcore binary and config file
  1. cd $GOPATH/src/github.com/kubeedge/kubeedge/cloud
  2. # run edge controller
  3. # `conf/` should be in the same directory as the cloned KubeEdge repository
  4. # verify the configurations before running cloud(cloudcore)
  5. mkdir -p ~/cmd/conf
  6. cp cloudcore ~/cmd/
  7. cp -rf conf/* ~/cmd/conf/

Note ~/cmd/ dir is an example, in the following examples we continue to use ~/cmd/ as the binary startup directory. You can move cloudcore or edgecore binary to anywhere, but you need to create conf dir in the same directory as binary.

  • Set cloudcore config file
  1. cd ~/cmd/conf
  2. vim controller.yaml

verify the configurations before running cloudcore

  1. controller:
  2. kube:
  3. master: # kube-apiserver address (such as:http://localhost:8080)
  4. namespace: ""
  5. content_type: "application/vnd.kubernetes.protobuf"
  6. qps: 5
  7. burst: 10
  8. node_update_frequency: 10
  9. kubeconfig: "/root/.kube/config" #Enter absolute path to kubeconfig file to enable https connection to k8s apiserver, if master and kubeconfig are both set, master will override any value in kubeconfig.
  10. cloudhub:
  11. protocol_websocket: true # enable websocket protocol
  12. port: 10000 # open port for websocket server
  13. protocol_quic: true # enable quic protocol
  14. quic_port: 10001 # open prot for quic server
  15. max_incomingstreams: 10000 # the max incoming stream for quic server
  16. enable_uds: true # enable unix domain socket protocol
  17. uds_address: unix:///var/lib/kubeedge/kubeedge.sock # unix domain socket address
  18. address: 0.0.0.0
  19. ca: /etc/kubeedge/ca/rootCA.crt
  20. cert: /etc/kubeedge/certs/edge.crt
  21. key: /etc/kubeedge/certs/edge.key
  22. keepalive-interval: 30
  23. write-timeout: 30
  24. node-limit: 10
  25. devicecontroller:
  26. kube:
  27. master: # kube-apiserver address (such as:http://localhost:8080)
  28. namespace: ""
  29. content_type: "application/vnd.kubernetes.protobuf"
  30. qps: 5
  31. burst: 10
  32. kubeconfig: "/root/.kube/config" #Enter absolute path to kubeconfig file to enable https connection to k8s apiserver,if master and kubeconfig are both set, master will override any value in kubeconfig.

cloudcore default supports https connection to Kubernetes apiserver, so you need to check whether the path for controller.kube.kubeconfig and devicecontroller.kube.kubeconfig exist, but if master and kubeconfig are both set, master will override any value in kubeconfig.Check whether the cert files for cloudhub.ca, cloudhub.cert,cloudhub.key exist.

  • Run cloudcore
  1. cd ~/cmd/
  2. nohup ./cloudcore &
  • Run cloudcore with systemd

It is also possible to start the cloudcore with systemd. If you want, you could use the example systemd-unit-file. The following command will show you how to setup this:

  1. sudo ln build/tools/cloudcore.service /etc/systemd/system/cloudcore.service
  2. sudo systemctl daemon-reload
  3. sudo systemctl start cloudcore

Note: Please fix ExecStart path in cloudcore.service. Do NOT use relative path, use absoulte path instead.

If you also want also an autostart, you have to execute this, too:

  1. sudo systemctl enable cloudcore

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.

  • Copy the $GOPATH/src/github.com/kubeedge/kubeedge/build/node.json file and change metadata.name to the name of the edge node
  1. mkdir ~/cmd/yaml
  2. cp $GOPATH/src/github.com/kubeedge/kubeedge/build/node.json ~/cmd/yaml
  • Make sure role is set to edge for the node. For this a key of the form "node-role.kubernetes.io/edge" must be present in labels tag of metadata.

  • Please ensure to add the label node-role.kubernetes.io/edge to the build/node.json file.

  1. {
  2. "kind": "Node",
  3. "apiVersion": "v1",
  4. "metadata": {
  5. "name": "edge-node",
  6. "labels": {
  7. "name": "edge-node",
  8. "node-role.kubernetes.io/edge": ""
  9. }
  10. }
  11. }

Note: you need to remember metadata.name , because edgecore need it.

  • If role is not set for the node, the pods, configmaps and secrets created/updated in the cloud cannot be synced with the node they are targeted for.

  • Deploy edge node (you must run on cloud side)

  1. kubectl apply -f ~/cmd/yaml/node.json
  • Transfer certificate files to the edge node, because edgecore use these certificate files to connection cloudcore

Setup edge side

Clone KubeEdge

  1. git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge
  2. cd $GOPATH/src/github.com/kubeedge/kubeedge

Run Edge

Run as a binary
  • Build Edge
  1. cd $GOPATH/src/github.com/kubeedge/kubeedge
  2. make all WHAT=edgecore

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.

  1. cd $GOPATH/src/github.com/kubeedge/kubeedge/edge
  2. 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:

  1. apt-get install upx-ucl
  2. cd $GOPATH/src/github.com/kubeedge/kubeedge/edge
  3. 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 memorymore than once etc. are applicable here as well.

  • Set edgecore config file
  1. mkdir ~/cmd/conf
  2. cp $GOPATH/src/github.com/kubeedge/kubeedge/edge/conf/* ~/cmd/conf
  3. vim ~/cmd/conf/edge.yaml

Note: ~/cmd/ dir is also an example as well as cloudcore, conf/ should be in the same directory as edgecore binary,

verify the configurations before running edgecore

  1. mqtt:
  2. server: tcp://127.0.0.1:1883 # external mqtt broker url.
  3. internal-server: tcp://127.0.0.1:1884 # internal mqtt broker url.
  4. mode: 0 # 0: internal mqtt broker enable only. 1: internal and external mqtt broker enable. 2: external mqtt broker
  5. enable only.
  6. qos: 0 # 0: QOSAtMostOnce, 1: QOSAtLeastOnce, 2: QOSExactlyOnce.
  7. retain: false # if the flag set true, server will store the message and can be delivered to future subscribers.
  8. session-queue-size: 100 # A size of how many sessions will be handled. default to 100.
  9.  
  10. edgehub:
  11. websocket:
  12. url: wss://0.0.0.0:10000/e632aba927ea4ac2b575ec1603d56f10/edge-node/events
  13. certfile: /etc/kubeedge/certs/edge.crt
  14. keyfile: /etc/kubeedge/certs/edge.key
  15. handshake-timeout: 30 #second
  16. write-deadline: 15 # second
  17. read-deadline: 15 # second
  18. quic:
  19. url: 127.0.0.1:10001
  20. cafile: /etc/kubeedge/ca/rootCA.crt
  21. certfile: /etc/kubeedge/certs/edge.crt
  22. keyfile: /etc/kubeedge/certs/edge.key
  23. handshake-timeout: 30 #second
  24. write-deadline: 15 # second
  25. read-deadline: 15 # second
  26. controller:
  27. protocol: websocket # websocket, quic
  28. heartbeat: 15 # second
  29. project-id: e632aba927ea4ac2b575ec1603d56f10
  30. node-id: edge-node
  31.  
  32. edged:
  33. register-node-namespace: default
  34. hostname-override: edge-node
  35. interface-name: eth0
  36. edged-memory-capacity-bytes: 7852396000
  37. node-status-update-frequency: 10 # second
  38. device-plugin-enabled: false
  39. gpu-plugin-enabled: false
  40. image-gc-high-threshold: 80 # percent
  41. image-gc-low-threshold: 40 # percent
  42. maximum-dead-containers-per-container: 1
  43. docker-address: unix:///var/run/docker.sock
  44. runtime-type: docker
  45. remote-runtime-endpoint: unix:///var/run/dockershim.sock
  46. remote-image-endpoint: unix:///var/run/dockershim.sock
  47. runtime-request-timeout: 2
  48. podsandbox-image: kubeedge/pause:3.1 # kubeedge/pause:3.1 for x86 arch , kubeedge/pause-arm:3.1 for arm arch, kubeedge/pause-arm64 for arm64 arch
  49. image-pull-progress-deadline: 60 # second
  50. cgroup-driver: cgroupfs
  51. node-ip: ""
  52. cluster-dns: ""
  53. cluster-domain: ""
  54.  
  55. mesh:
  56. loadbalance:
  57. strategy-name: RoundRobin
  • If you have run mosquitto on your edge host, please set mqtt.mode to 2.
  • To use KubeEdge in double mqtt or external mode (set mqtt.mode to 1), you need to make sure that mosquitto or emqx edge is installed on the edge node as an MQTT Broker.
  • Check whether the cert files for edgehub.websocket.certfile and edgehub.websocket.keyfile exist.
  • Check whether the cert files for edgehub.quic.certfile ,edgehub.quic.keyfile and edgehub.quic.cafile exist. If those files not exist, you need to copy them from cloud side.
  • Check edged.podsandbox-image
    • kubeedge/pause-arm:3.1 for arm arch
    • kubeedge/pause-arm64:3.1 for arm64 arch
    • kubeedge/pause:3.1 for x86 arch
  • Update the IP address of the master in the edgehub.websocket.url field. You need set cloudcore ip address.
  • If you use quic protocol, please update the IP address of the master in the edgehub.quic.url field. You need set cloudcore ip address.
  • replace edge-node with edge node name in edge.yaml for the below fields :
    • websocket:URL
    • controller:node-id
    • edged:hostname-override
    • Run edgecore
  1. cp $GOPATH/src/github.com/kubeedge/kubeedge/edge/edgecore ~/cmd/
  2. cd ~/cmd
  3. ./edgecore
  4. # or
  5. nohup ./edgecore > edgecore.log 2>&1 &

Note: Please run edgecore using the users who have root permission.

  • Run edgecore with systemd

It is also possible to start the edgecore with systemd. If you want, you could use the example systemd-unit-file. The following command will show you how to setup this:

  1. sudo ln build/tools/edgecore.service /etc/systemd/system/edgecore.service
  2. sudo systemctl daemon-reload
  3. sudo systemctl start edgecore

Note: Please fix ExecStart path in edgecore.service. Do NOT use relative path, use absoulte path instead.

If you also want also an autostart, you have to execute this, too:

  1. sudo systemctl enable edgecore

Check status

After the Cloud and Edge parts have started, you can use below command to check the edge node status.

  1. kubectl get nodes

Please make sure the status of edge node you created is ready.

Deploy Application on cloud side

Try out a sample application deployment by following below steps.

  1. kubectl apply -f $GOPATH/src/github.com/kubeedge/kubeedge/build/deployment.yaml

Note: Currently, for applications running on edge nodes, we don’t support kubectl logs and kubectl exec commands(will support in future release), support pod to pod communication running on edge nodes in same subnet using edgemesh.

Then you can use below command to check if the application is normally running.

  1. kubectl get pods

Run Tests

Run Edge Unit Tests

  1. make edge_test

To run unit tests of a package individually.

  1. export GOARCHAIUS_CONFIG_PATH=$GOPATH/src/github.com/kubeedge/kubeedge/edge
  2. cd <path to package to be tested>
  3. go test -v

Run Edge Integration Tests

  1. make edge_integration_test

Details and use cases of integration test framework

Please find the link to use cases of intergration test framework for KubeEdge.