-
Notifications
You must be signed in to change notification settings - Fork 0
Kube
webthing-iotjs was made to target MCU but it can also support other platforms like GnuLinux and its containers (ie: Docker).
This page will explain how to create microservices and run them in a cluster.
There are various Kubernetes (K8S) distributions, a few are described from simplest to more hazardous environments.
Cannonical is providing to community a simplified K8S snap package, Even if snap is part of Ubuntu, it is also also supported by others GnuLinux distros:
Note that MicroK8s was designed to build a single node cluster (WIP for multinode) :
project="webthing-iotjs"
org="rzrfreefr"
image="${org}/${project}:latest"
kubectl=microk8s.kubectl
port=8888
sudo apt-get install snapd curl
sudo snap install microk8s --classic --channel=1.14/stable
$kubectl cluster-info
#| Kubernetes master is running at https://127.0.0.1:16443
$kubectl get services
#| kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 14h
microk8s.enable dns # Will restart kubelet
$kubectl run "${project}" --image="${image}"
$kubectl describe deployment/$name
# Wait running pod
time $kubectl get all --all-namespaces | grep "pod/$name" | grep ' Running ' \
|| time $kubectl get all --all-namespaces
pod=$($kubectl get all --all-namespaces \
| grep -o "pod/${project}.*" | cut -d/ -f2 | awk '{ print $1}' \
|| echo failure) && echo "# pod=${pod}"
# Wait until ready
$kubectl describe pod "$pod" | grep 'Status: * Running' \
|| $kubectl describe pod "$pod"
# Try server (direct)
ip=$(microk8s.kubectl describe pod "$pod" | grep 'IP:' | awk '{ print $2 }')
curl -i http://$ip:${port}/1/properties \
|| curl -i http://$ip:${port}
#| {"level":10.185334482308157}
# Remove service and uninstall
$kubectl delete deployment/${name}
$kubectl get all --all-namespaces | grep ${name}
microk8s.reset
sudo snap remove microk8s
OK we have verified our base, Next step is to deploy a service.
Reinstall microk8s
name="webthing-iotjs"
url="https://github.com/raw/rzr/${name}/master/extra/tools/kube/$name.yml"
public_port=30080
port=8888
unit=microk8s
export PATH="/snap/microk8s/current/:/snap/bin/:$PATH"
kubectl="microk8s.kubectl"
namespace="k8s.io" # https://microk8s.io/docs/working
time $kubectl apply -f "${url}" \
|| curl "$url"
#| deployment.extensions/webthing-iotjs created
#| service/webthing-iotjs created
public_port=$($kubectl get svc ${name} -o=jsonpath="{.spec.ports[?(@.port==$port)].nodePort}") && echo $public_port
public_url="http://127.0.0.1:${public_port}" && echo "# log: public_url=${public_url}"
#| log: public_url=http://127.0.0.1:30080
curl -i ${public_url}/1/properties
#| {"level":3.9673602144479743}
Next step is to setup ingress and public backend.
K3S is another distribution designed for Edge devices, Make sure to uninstall other K8S to avoid overlap of resources
project="webthing-iotjs"
org="rzrfreefr"
image="${org}/${project}:latest"
kubectl="sudo kubectl"
curl -sfL https://get.k3s.io | sh -
sudo snap remove microk8s
sudo systemctl restart k3s.service
sudo systemctl status k3s.service
$kubectl get nodes
#| ... Ready master 51s v1.14.4-k3s.1
$kubectl run "${project}" --image="${image}"
pod=$($kubectl get all --all-namespaces \
| grep -o "pod/${project}.*" | cut -d/ -f2 | awk '{ print $1}' \
|| echo failure) && echo pod="$pod"
$kubectl describe pod "$pod" | grep 'Status: Running'
ip=$($kubectl describe pod "$pod" | grep 'IP:' | awk '{ print $2 }') && echo "ip=${ip}"
curl http://$ip:8888
#| [{"name":"My Lamp"," ...
sudo grep server /etc/rancher/k3s/k3s.yaml
#| server: https://localhost:6443
curl -k -i https://localhost:6443
#| HTTP/1.1 401 Unauthorized
#| Content-Type: application/json
#| Www-Authenticate: Basic realm="kubernetes-master"
# token=$(sudo cat /var/lib/rancher/k3s/server/node-token)
# curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=${token} sh -
An other K8S system designed for prototyping (WIP)
To get started see README.md of :
Or try the webthing-go version as explained at:
- https://github.com/rzr/webthing-go/blob/master/docs/kube.md
- https://github.com/rzr/webthing-go/tree/master/docs
Kadmin is the tool for multi node clustering
Check Concept page for overview, Gateway to get started, IotJs page to install runtime to build webthing as explained in Home page.
For further experiments check Social and Sensor, or Extra parts like WebApp (for Tizen or PWA) or MCU info about running on other microcontrollers not supported by TizenRT.
While Home focus mostly on using iotjs to build webthings (on GNU/Linux or TizenRT for ARTIK05X devices).
This document is still in draft state, but reviews are always welcome, if you try to replicate it and stuck on missing instructions I would appreciate that you file issues or even better make pull request (just edit in github) that insert "TODO marks" in following chapters, like:
- TODO: please explain more this chapter and then remove this TODO line
Community contributions are welcome at:
Support is also possible, ask in:
- https://github.com/rzr/webthing-iotjs
- irc://irc.mozilla.org/#iot
WARNING: Developement branches could break over time.
Instead of maintaining "quick and dirty" demo code, I decided to split demo in smaller independents parts (which can reused) and I am upstreaming the most I can.
Then support can be done on mainline branches (or released versions).
Note that, Upstreaming can be a slow process, so snapshots links will remain until 100% of code is upstreamed.
Licence:
Reference documentation is at:
-
Concept:
- Demo Concept and Architecture
-
Gateway:
- Getting started with Mozilla IoT gateway
-
IotJs:
- Install IoT.js needed to run webthings
-
Home:
- Welcome page to build WebThings using IotJs
-
Social:
- Notification service using Mastodon FLOSS
-
TizenRT:
- webthing-iotjs on ARTIK05x
-
Sensor: and Actuator
- Physical interactions
-
Extra hints:
- Docker: About running in container
- MCU: About microcontrollers (not supported by TizenRT)
- WebApp: Alternate browser (Tizen and PWA)
- GnuLinux: Article about Edison and other
- Raspbian: Article about RaspberryPi
- Arduino: Alt For atmel or Esprissif boards
- DigitalTwins : WiP experiments
- TODO: Work in progress