Upload
francesco-uliana
View
182
Download
0
Embed Size (px)
Citation preview
DOCKER FOR INTERNET OF THINGS4DEVOPS + DOCKER ITALIA
27-01-2017
FRANCESCO ULIANA@warrior10111
github.com/francescou
www.uliana.it/francesco
INTRODUCTION
INTERNET OF THINGSconnected devicescommunicationlow power
DOCKERpack, ship and run any application as a lightweightcontainerhardware-agnostic and platform-agnosticswarm mode
MICROSERVICESservice-oriented architectures (SOA)flexible, independently deployable so�waresystems.
EXAMPLE PROJECThttps://github.com/francescou/docker-for-IoT
light sensors networkcollect sensors dataautomatically adapt light temperatureweb application to monitor/interoperate with thesystem
HARDWARE
Raspberry pi (ARM)
ESP8266 (+ some sensors)
GETTING STARTED
HYPRIOT OSdd if=hypriot-rpi-...imgof=/dev/mmcblk0 bs=1M
edit hostname in /boot/device-init.yaml
https://blog.hypriot.com/
docker info
it works on every machine running Docker with oneexception.
Raspberry pi CPU architecture is ARM - apps you usehave to be packaged specifically for ARM architecture!
docker run -p 80:80 hypriot/rpi-busybox-httpd
SWARM MODEdocker swarm init --advertise-addr
<MANAGER-IP>
docker swarm join --token SWMTKN-...192.168.99.100:2377
docker node lshttps://docs.docker.com/engine/swarm/swarm-
tutorial/create-swarm/
RPI CLUSTER MONITORINGInfluxDBGrafanaTelegraf
docker service create \ --name influxdb \ --network tick \ --publish 8086:8086 \ --constraint 'node.hostname==pi-clear' \ --mount type=bind,source=/influxdb/,destination=/var/lib/influxdb/ \ francesco-arch:5000/influxdb:1.0
TELEGRAF INPUTScpudiskdiskiomemprocessesdocker
docker service create \ --name telegraf \ --network tick \ francesco-arch:5000/telegraf:1.5
dashboard - Grafana
docker service create \ --name grafana \ --network tick \ --publish 3000:3000 \ --constraint 'node.hostname==pi-clear' \ --mount type=bind,source=/grafana/,destination=/var/lib/grafana/ francesco-arch:5000/grafana:1.0
SENSORS DATACOLLECTION
MQTT - async communicationTelegraf (input mqtt)
MQTTpublish/subscribe messaging transport protocol.Lightweight and Bandwidth Efficient
MQTT BROKER(i.e. )https://github.com/mcollina/mosca
docker service create \ --name mosca \ --network tick \ --publish 1883:1883 \ francesco-arch:5000/mosca:1.1
REAL TIME MONITOR...websockets!
Node.js + socket.iovar app = require('http').createServer(handler) var io = require('socket.io')(app); var mqtt = require('mqtt') var client = mqtt.connect('mqtt://mosca')
client.on('connect', function () { client.subscribe('sensors/#'); });
app.listen(8180);
io.on('connection', function (socket) { client.on('message', function (topic, message) { var value = message.toString().split('=')[1]; socket.emit('news', { value: value
LIGHT SWITCHclient = paho.Client() client.connect("mosca", 1883, 60) client.publish("status/switch", payload='switch light=' + str(status), qos=
FLASK: PYTHONMICROFRAMEWORK
from flask import Flask app = Flask(__name__)
@app.route("/") def hello(): return "Hello World!"
if __name__ == "__main__": app.run()
ALERTING
grafana alertingsensors datasystem metricsmultiple notification systems (e.g. slack, e-mail...)
LOGS
multiple servicesmultiple containersmultiple docker hosts
docker logs -f grafana.1.7io0044bl8
multi tail?grep?alerting?
LOG CENTRALIZATIONelasticsearch + logstash + kibana (elastic stack)graylog2fluentd
FLUENTDhttp://www.fluentd.org/guides/recipes/docker-logging
docker run --name hello --log-driver fluentd --log-opt fluentd-address=pi-lagom:24224 hypriot/rpi-alpine echo hello
$ tail -1 /data/docker.20170121.b5469f127f89950d6.log
20170121T201522+0000 docker.659579b7be4f {"container_id":"...","container_name":"/hello", "source":"stdout","log":"hello"}
CHATBOT (Node.js)https://github.com/howdyai/botkit
var Botkit = require('./lib/Botkit.js');
var controller = Botkit.slackbot({ debug: true, });
var bot = controller.spawn({ token: process.env.token }).startRTM();
controller.hears(['hello', 'hi'],'direct_message,direct_mention,mention' bot.reply(message, 'Hello.'); });
PUTTING IT ALL TOGETHERtraefik to reverse proxy
light switchgrafanareal time monitoring
HEALTH CHECKINGHEALTHCHECK CMD curl --fail
http://localhost:3000/health || exit1
YES BUT...WHY???real world use caseslow bandwidth / low processing powerenforce resiliency
Q&A