KubeEdge Setup Guide#
A complete hands-on guide to setting up a KubeEdge cloud-edge environment, managing IoT devices, and troubleshooting common issues.
Prerequisites#
Ensure you have the required tools installed before starting:
# Verify required tools
docker --version
kubectl version --client
go version # Optional, for building from sourceYou will need:
- A Kubernetes cluster (cloud side)
- Ubuntu/CentOS machines for edge nodes
- Network connectivity between cloud and edge
Step 1: Prepare Your Environment#
# Set up environment variables
export KUBEEDGE_VERSION=v1.18.0
export CLOUD_MASTER_IP=<your-k8s-master-ip>
export EDGE_NODE_NAME=edge-node-01
# Clean up any previous installations
sudo systemctl stop edgecore 2>/dev/null || true
sudo systemctl stop cloudcore 2>/dev/null || trueStep 2: Install CloudCore (Cloud Side)#
# Download and install keadm
curl -L https://github.com/kubeedge/kubeedge/releases/download/${KUBEEDGE_VERSION}/keadm-${KUBEEDGE_VERSION}-linux-amd64.tar.gz | tar xz
sudo mv keadm-${KUBEEDGE_VERSION}-linux-amd64/keadm/keadm /usr/local/bin/
# Initialize CloudCore on your Kubernetes cluster
sudo keadm init \
--advertise-address=${CLOUD_MASTER_IP} \
--kubeedge-version=${KUBEEDGE_VERSION}
# Verify CloudCore is running
kubectl get pods -n kubeedgeStep 3: Get Token for Edge Nodes#
# Generate token for edge node registration
sudo keadm gettoken
# Output will look like:
# 27a37ef16159f7d3be8fae95d588b79b3adaaf92727b72659eb89758c66ffda2.eyJh...Step 4: Join Edge Node#
Run the following on your edge machine:
# Download keadm on edge node
curl -L https://github.com/kubeedge/kubeedge/releases/download/${KUBEEDGE_VERSION}/keadm-${KUBEEDGE_VERSION}-linux-amd64.tar.gz | tar xz
sudo mv keadm-${KUBEEDGE_VERSION}-linux-amd64/keadm/keadm /usr/local/bin/
# Join the edge node to CloudCore
sudo keadm join \
--cloudcore-ipport=${CLOUD_MASTER_IP}:10000 \
--edgenode-name=${EDGE_NODE_NAME} \
--token=<token-from-step-3> \
--kubeedge-version=${KUBEEDGE_VERSION}
# Verify edge node is running
sudo systemctl status edgecoreStep 5: Verify Cloud-Edge Connection#
Back on the cloud side, check if the edge node is connected:
kubectl get nodes
# Expected output:
# NAME STATUS ROLES AGE VERSION
# master Ready control-plane,master 1d v1.21.0
# edge-node-01 Ready agent,edge 5m v1.19.3-kubeedge-v1.18.0Step 6: Deploy Your First Edge Application#
# Create a simple nginx deployment for edge
cat << 'EOF' | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-edge
spec:
replicas: 1
selector:
matchLabels:
app: nginx-edge
template:
metadata:
labels:
app: nginx-edge
spec:
nodeSelector:
kubernetes.io/hostname: edge-node-01
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
resources:
limits:
memory: "128Mi"
cpu: "200m"
---
apiVersion: v1
kind: Service
metadata:
name: nginx-edge-service
spec:
selector:
app: nginx-edge
ports:
- port: 80
targetPort: 80
type: NodePort
EOFStep 7: Verify Edge Deployment#
# Check if pod is running on edge node
kubectl get pods -o wide
# Test offline capability — disconnect edge node from network
# The pod should continue running locally!
# Reconnect and confirm synchronization resumes
kubectl describe node edge-node-01Device Management with KubeEdge#
Step 1: Define a Device Model#
cat << 'EOF' | kubectl apply -f -
apiVersion: devices.kubeedge.io/v1alpha2
kind: DeviceModel
metadata:
name: temperature-model
namespace: default
spec:
properties:
- name: temperature
description: Temperature reading in Celsius
type:
string:
accessMode: ReadOnly
defaultValue: "0"
- name: humidity
description: Humidity percentage
type:
string:
accessMode: ReadOnly
defaultValue: "0"
EOFStep 2: Create a Device Instance#
cat << 'EOF' | kubectl apply -f -
apiVersion: devices.kubeedge.io/v1alpha2
kind: Device
metadata:
name: temp-sensor-01
namespace: default
labels:
model: temperature-model
location: factory-floor
spec:
deviceModelRef:
name: temperature-model
protocol:
mqtt:
server: tcp://localhost:1883
nodeSelector:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- edge-node-01
data:
dataTopic: "$hw/events/device/temp-sensor-01/data/update"
dataTopicTwin: "$hw/events/device/temp-sensor-01/twin/update"
EOFStep 3: Deploy a Device Monitor Application#
cat << 'EOF' | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: temperature-monitor
spec:
replicas: 1
selector:
matchLabels:
app: temperature-monitor
template:
metadata:
labels:
app: temperature-monitor
spec:
nodeSelector:
kubernetes.io/hostname: edge-node-01
containers:
- name: monitor
image: eclipse-mosquitto:latest
command: ["/bin/sh", "-c"]
args:
- |
while true; do
mosquitto_pub -h localhost \
-t '$hw/events/device/temp-sensor-01/data/update' \
-m '{"temperature":"$(( RANDOM % 40 + 10 ))","humidity":"$(( RANDOM % 100 ))"}'
sleep 30
done
resources:
limits:
memory: "64Mi"
cpu: "100m"
EOFAdvanced: Multi-Cloud Edge Setup#
# Deploy CloudCore on AWS
keadm init --advertise-address=<aws-ip>
# Connect edge nodes from different providers
keadm join --cloudcore-ipport=<aws-ip>:10000 --edgenode-name=azure-edge
keadm join --cloudcore-ipport=<aws-ip>:10000 --edgenode-name=gcp-edge
keadm join --cloudcore-ipport=<aws-ip>:10000 --edgenode-name=onprem-edgeAdvanced: Edge AI / ML Deployment#
apiVersion: apps/v1
kind: Deployment
metadata:
name: edge-ai-inference
spec:
template:
spec:
nodeSelector:
kubernetes.io/hostname: edge-gpu-node
containers:
- name: tensorflow-serving
image: tensorflow/serving:latest-gpu
resources:
limits:
nvidia.com/gpu: 1Troubleshooting Common Issues#
Issue 1: Edge Node Not Connecting#
# Check CloudCore logs
kubectl logs -n kubeedge deployment/cloudcore
# Check EdgeCore logs on edge node
sudo journalctl -u edgecore.service -f
# Verify network connectivity
curl -k https://<cloudcore-ip>:10000/readyz
# Reset and rejoin if needed
sudo keadm reset
sudo keadm join --cloudcore-ipport=<ip>:10000 --token=<new-token>Issue 2: Device Not Reporting Data#
# Check device twin status
kubectl describe device temp-sensor-01
# Verify MQTT broker connectivity
mosquitto_sub -h localhost -t '$hw/events/device/+/twin/update'
# Check device mapper logs
kubectl logs -n kubeedge deployment/device-mapper
# Test device protocol manually
mosquitto_pub -h localhost \
-t '$hw/events/device/temp-sensor-01/data/update' \
-m '{"temperature":"25"}'Issue 3: Pod Not Scheduling to Edge#
# Check node labels and selectors
kubectl get nodes --show-labels
# Inspect pod spec for nodeSelector issues
kubectl describe pod <pod-name>
# Check for resource constraints
kubectl describe node <edge-node-name>
# Check for taints and tolerations
kubectl describe node <edge-node-name> | grep -i taintIssue 4: MQTT Messages Not Flowing#
# Test MQTT connectivity
mosquitto_pub -h <broker-ip> -t test/topic -m "hello"
mosquitto_sub -h <broker-ip> -t test/topic
# Check EventBus logs
sudo journalctl -u eventbus.service -f
# Verify device mapper configuration
kubectl get devicemodel,device -o wideDevelopment Environment Setup#
# Clone the KubeEdge repository
git clone https://github.com/kubeedge/kubeedge.git
cd kubeedge
# Install Go dependencies
go mod download
# Build all components
make all
# Run unit tests
make test
# Build specific components
make cloudcore
make edgecore
make keadm
# Run integration and e2e tests
make test-integration
make e2e-test
make device-testKey Repository Directories#
| Directory | Purpose |
|---|---|
/cloud | CloudCore components (cloud-side logic) |
/edge | EdgeCore components (edge-side logic) |
/keadm | Administration tools |
/pkg | Shared packages and utilities |
/tests | Test suites and integration tests |
/docs | Documentation and proposals |
/staging | Staging area for new features |
Useful Resources#
| Resource | Link |
|---|---|
| Official Docs | https://kubeedge.io/docs/ |
| GitHub Repository | https://github.com/kubeedge/kubeedge |
| Installation Guide | https://kubeedge.io/docs/setup/install-with-keadm/ |
| Device Management | https://kubeedge.io/docs/developer/device_crd/ |
| Troubleshooting | https://kubeedge.io/docs/troubleshooting/troubleshooting/ |
| Architecture Overview | https://kubeedge.io/docs/architecture/overview/ |
| Community Slack | https://kubeedge.slack.com |
| Contributing Guide | https://github.com/kubeedge/kubeedge/blob/master/CONTRIBUTING.md |