Deploying EMQ X Edge on Raspberry Pi Using K3S
K3S is a light-weight Kubernetes environment, this article shows you how to deploy EMQ X Edge on Raspberry Pi using K3S.
EMQ X Edge is a light-weight edge computing message middleware for Internet of Things, which supports deployment of edge hardware in a resource-constrained environment.
Environment
It is required that the Raspberry Pi can visit the internet to install EMQ X Edge using K3S. Here we will using three Raspberry Pis to demonstrate our deployment.
=======================================
|Host Name | IP Address | Role |
=======================================
|raspberrypi | 192.168.1.99 | server |
---------------------------------------
|emqx1 | 192.168.1.100 | agent |
---------------------------------------
|emqx2 | 192.168.1.101 | agent |
---------------------------------------
Preparation
Download K3S
Currently K3S supports x86_64, armhf and arm64. For the Raspberry Pi, the one for armhf should be installed.
$ wget https://github.com/rancher/k3s/releases/download/v0.2.0/k3s-armhf
$ mv k3s-armhf /usr/local/bin/k3s
$ chmod +x /usr/local/bin/k3s
Start the server
$ sudo k3s server
Create a cluster for K3S
Open the /var/lib/rancher/k3s/server/node-token
file on server
node to get node token
.
$ NODE_TOKEN=$(sudo cat /var/lib/rancher/k3s/server/node-token)
On the agent
node, run following command to join the K3S cluster:
$ sudo k3s agent --server https://192.168.1.99:6443 --token ${NODE_TOKEN}
Use kubectl to manage K3S cluster from remote (optional)
Any device which can connect to K3S cluster we created above can manage this cluster using kubectl
by doing following:
- Install the
kubectl
on the managing device - Copy the
/etc/rancher/k3s/k3s.yaml
to the managing device in file~/.kube/config
- Modify
~/.kube/config
, changehttps://localhost:6443
tohttps://192.168.1.99:6443
- Manage the K3S cluster using
kubectl
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
emqx2 Ready <none> 29m v1.13.4-k3s.1
emqx1 Ready <none> 29m v1.13.4-k3s.1
raspberrypi Ready <none> 31m v1.13.4-k3s.1
Install Helm
Install Helm client
Download and unzip Helm release form https://github.com/kubernetes/helm/releases
and copy it to /usr/local/bin/helm
.
Install Tiller server
Create a Service Account for Tiller.
$ kubectl create serviceaccount tiller --namespace kube-system
Grant cluster-admin
privilege to tiller:
Add the tiller to the cluster-admin role by appending following to rbac-config.yaml
file:
$ cat <<EOF >rbac-config.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
EOF
Run kubectl create -f
to give tiller the privilege of cluster-admin:
$ kubectl create -f rbac-config.yaml
Install Tiller server
$ helm init --service-account tiller
Verify the installation
After the installation you can check it with the following command:
$ helm version
If it shows the correct Helm client and the Tiller server version, it means the installation is successful.
Or you can use kubectl
to check it:
$ kubectl get pods -n kube-system
Deploying the EMQ X Cluster
Deploy EMQ X using Helm
$ git clone https://github.com/emqx/emqx-chart $ cd emqx-chart $ helm install --name myemqx --set deployment.image="emqx/emqx-edge:latest" .
Check the state of EMQ X cluster
check the pods list.
$ kubectl get pods |grep myemqx myemqx-emqx-chart-54974fc5f5-v8chq 1/1 Running 0 2m9s myemqx-emqx-chart-54974fc5f5-zz9gc 1/1 Running 0 2m9s
Check the EMQ X cluster state.
$ kubectl exec myemqx-emqx-chart-54974fc5f5-v8chq /opt/emqx/bin/emqx_ctl cluster status
Cluster status: [{running_nodes,['emqx@10.42.2.11','emqx@10.42.1.15']}]
Welcome to our open source project github.com/emqx/emqx. Please visit the documentation for details.