Skip to content
Philippe Coval edited this page Aug 27, 2019 · 27 revisions

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.

MICROK8S:

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) :

MICROK8S : DEPLOY AND TEST

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.

MICROK8S: 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

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 -

MINIKUBE

An other K8S system designed for prototyping (WIP)

To get started see README.md of :

Or try the webthing-go version as explained at:

KUBERNETES/ KADMIN

Kadmin is the tool for multi node clustering

kubernetes

LICENSE: CC-BY-SA-4.0

INDEX

Clone this wiki locally