Add Edge Nodes

KubeSphere leverages KubeEdge, to extend native containerized application orchestration capabilities to hosts at edge. With separate cloud and edge core modules, KubeEdge provides complete edge computing solutions while the installation may be complex and difficult.

kubeedge_arch

Note

For more information about different components of KubeEdge, see the KubeEdge documentation.

This tutorial demonstrates how to add an edge node to your cluster.

Prerequisites

  • You have enabled KubeEdge.
  • You have an available node to serve as an edge node. The node can run either Ubuntu (recommended) or CentOS. This tutorial uses Ubuntu 18.04 as an example.
  • Edge nodes, unlike Kubernetes cluster nodes, should work in a separate network.

Configure an Edge Node

You need to install a container runtime and configure EdgeMesh on your edge node.

Install a container runtime

KubeEdge supports several container runtimes including Docker, containerd, CRI-O and Virtlet. For more information, see the KubeEdge documentation.

Note

If you use Docker as the container runtime for your edge node, Docker v19.3.0 or later must be installed so that KubeSphere can get Pod metrics of it.

Configure EdgeMesh

Perform the following steps to configure EdgeMesh on your edge node.

  1. Edit /etc/nsswitch.conf.

    1. vi /etc/nsswitch.conf
  2. Add the following content to this file:

    1. hosts: dns files mdns4_minimal [NOTFOUND=return]
  3. Save the file and run the following command to enable IP forwarding:

    1. sudo echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
  4. Verify your modification:

    1. sudo sysctl -p | grep ip_forward

    Expected result:

    1. net.ipv4.ip_forward = 1

Create Firewall Rules and Port Forwarding Rules

To make sure edge nodes can successfully talk to your cluster, you must forward ports for outside traffic to get into your network. Specifically, map an external port to the corresponding internal IP address (control plane node) and port based on the table below. Besides, you also need to create firewall rules to allow traffic to these ports (10000 to 10004).

Note

In ClusterConfiguration of the ks-installer, if you set an internal IP address, you need to set the forwarding rule. If you have not set the forwarding rule, you can directly connect to ports 30000 to 30004.

FieldsExternal PortsFieldsInternal Ports
cloudhubPort10000cloudhubNodePort30000
cloudhubQuicPort10001cloudhubQuicNodePort30001
cloudhubHttpsPort10002cloudhubHttpsNodePort30002
cloudstreamPort10003cloudstreamNodePort30003
tunnelPort10004tunnelNodePort30004

Add an Edge Node

  1. Log in to the console as admin and click Platform in the upper-left corner.

  2. Select Cluster Management and navigate to Edge Nodes under Nodes.

    Note

    If you have enabled multi-cluster management, you need to select a cluster first.

  3. Click Add. In the dialog that appears, set a node name and enter an internal IP address of your edge node. Click Validate to continue.

    Note

    • The internal IP address is only used for inter-node communication and you do not necessarily need to use the actual internal IP address of the edge node. As long as the IP address is successfully validated, you can use it.
    • It is recommended that you check the box to add the default taint.
  4. Copy the command automatically created under Edge Node Configuration Command and run it on your edge node.

    Note

    Make sure wget is installed on your edge node before you run the command.

  5. Close the dialog, refresh the page, and the edge node will appear in the list.

    Note

    After an edge node is added, if you cannot see CPU and memory resource usage on the Edge Nodes page, make sure Metrics Server 0.4.1 or later is installed in your cluster.

Collect Monitoring Information on Edge Nodes

To collect monitoring information on edge node, you need to enable metrics_server in ClusterConfiguration and edgeStream in KubeEdge.

  1. On the KubeSphere web console, choose Platform > Cluster Management.

  2. On the navigation pane on the left, click CRDs.

  3. In the search bar on the right pane, enter clusterconfiguration, and click the result to go to its details page.

  4. Click Add Edge Nodes - 图2 on the right of ks-installer, and click Edit YAML.

  5. Search for metrics_server, and change the value of enabled from false to true.

    1. metrics_server:
    2. enabled: true # Change "false" to "true".
  6. Click OK in the lower right corner to save the change.

  7. Open the /etc/kubeedge/config file, search for edgeStream, change false to true, and save the change.

    1. cd /etc/kubeedge/config
    2. vi edgecore.yaml
    1. edgeStream:
    2. enable: true #Change "false" to "true".。
    3. handshakeTimeout: 30
    4. readDeadline: 15
    5. server: xx.xxx.xxx.xxx:10004 #If port forwarding is not configured, change the port ID to 30004 here.
    6. tlsTunnelCAFile: /etc/kubeedge/ca/rootCA.crt
    7. tlsTunnelCertFile: /etc/kubeedge/certs/server.crt
    8. tlsTunnelPrivateKeyFile: /etc/kubeedge/certs/server.key
    9. writeDeadline: 15
  8. Run the following command to restart edgecore.service.

    1. systemctl restart edgecore.service
  9. After an edge node joins your cluster, some Pods may be scheduled to it while they remains in the Pending state on the edge node. Due to the tolerations some DaemonSets (for example, Calico) have, you need to manually patch some Pods so that they will not be scheduled to the edge node.

  10. After an edge node joins your cluster, some Pods may be scheduled to it while they remains in the Pending state on the edge node. Due to the tolerations some DaemonSets (for example, Calico) have, in the current version (KubeSphere 3.3.0), you need to manually patch some Pods so that they will not be schedule to the edge node.

  1. #!/bin/bash
  2. NodeSelectorPatchJson='{"spec":{"template":{"spec":{"nodeSelector":{"node-role.kubernetes.io/master": "","node-role.kubernetes.io/worker": ""}}}}}'
  3. NoShedulePatchJson='{"spec":{"template":{"spec":{"affinity":{"nodeAffinity":{"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms":[{"matchExpressions":[{"key":"node-role.kubernetes.io/edge","operator":"DoesNotExist"}]}]}}}}}}}'
  4. edgenode="edgenode"
  5. if [ $1 ]; then
  6. edgenode="$1"
  7. fi
  8. namespaces=($(kubectl get pods -A -o wide |egrep -i $edgenode | awk '{print $1}' ))
  9. pods=($(kubectl get pods -A -o wide |egrep -i $edgenode | awk '{print $2}' ))
  10. length=${#namespaces[@]}
  11. for((i=0;i<$length;i++));
  12. do
  13. ns=${namespaces[$i]}
  14. pod=${pods[$i]}
  15. resources=$(kubectl -n $ns describe pod $pod | grep "Controlled By" |awk '{print $3}')
  16. echo "Patching for ns:"${namespaces[$i]}",resources:"$resources
  17. kubectl -n $ns patch $resources --type merge --patch "$NoShedulePatchJson"
  18. sleep 1
  19. done
  1. If you still cannot see the monitoring data, run the following command:

    1. journalctl -u edgecore.service -b -r

    Note

    If failed to check the running environment: kube-proxy should not running on edge node when running edgecore is displayed, refer to Step 8 to restart edgecore.service again.

Remove an Edge Node

Before you remove an edge node, delete all your workloads running on it.

  1. On your edge node, run the following commands:

    1. ./keadm reset
    1. apt remove mosquitto
    1. rm -rf /var/lib/kubeedge /var/lib/edged /etc/kubeedge/ca /etc/kubeedge/certs

    Note

    If you cannot delete the tmpfs-mounted folder, restart the node or unmount the folder first.

  2. Run the following command to remove the edge node from your cluster:

    1. kubectl delete node <edgenode-name>
  3. To uninstall KubeEdge from your cluster, run the following commands:

    1. helm uninstall kubeedge -n kubeedge
    1. kubectl delete ns kubeedge

    Note

    After uninstallation, you will not be able to add edge nodes to your cluster.