Skip to content

tech-sketch/mqtt-kube-operator

Repository files navigation

mqtt-kube-operator

Deploy a resource to remote Kubernetes using MQTT

TravisCI Status Docker Pulls

Description

When this container is deployed a Kubernetes cluster, the container subscribes two MQTT topics.
When a json string is received from subscribed topic, this container create / update / delete a Resource to its own Kubernetes.

Limitations

  • This program can operate only 4 resources below:
resource apiVersion
Deployment apps/v1
Service v1
ConfigMap v1
Secret v1
  • This program can operate only default namespace.

Environment Variables

This REST API accept Environment Variables like below:

Environment Variable Summary
LOG_LEVEL log level
MQTT_USE_TLS set false when connecting local MQTT Broker without TLS
MQTT_TLS_CA_PATH path to cafile used to connect MQTT Broker
MQTT_USERNAME username used to connect MQTT Broker
MQTT_PASSWORD password used to connect MQTT Broker
MQTT_HOST hostname of MQTT Broker
MQTT_PORT port of MQTT Broker
DEVICE_TYPE device type which is registered to iotagent-ul of FIWARE
DEVICE_ID device id which is registered to iotagent-ul of FIWARE
REPORT_INTERVAL_SEC report interval seconds (default 1 second)
USE_DEPLOYMENT_STATE_REPORTER set true when using deploymentStateReporter (default false)
USE_POD_STATE_REPORTER set true when using podStateReporter (default false)
REPORT_TARGET_LABEL_KEY the target label to gather resource status
KUBE_CONF_PATH if set, run this program locally using kubectl's configuration

Run this program locally

  1. set environment variables

    $ export KUBE_CONF_PATH=$HOME/.kube/config
    $ export MQTT_TLS_CA_PATH=/path/to/ca.crt
    $ export MQTT_USERNAME=mqtt_user
    $ export MQTT_PASSWORD=the_password_of_mqtt_user
    $ export MQTT_HOST=mqtt.example.com
    $ export MQTT_PORT=8883
    $ export DEVICE_TYPE=deployer
    $ export DEVICE_ID=delopyer_01
    $ export REPORT_INTERVAL_SEC=1
    $ export USE_DEPLOYMENT_STATE_REPORTER=true
    $ export REPORT_TARGET_LABEL_KEY=report
  2. get dependencies (at the first time only)

    $ make deps
  3. run program

    $ make run

Build container from source code

  1. build program and build container image

    $ make VERSION=0.2.0
  2. push container to DockerHub

    $ docker login
    $ make push VERSION=0.2.0

License

Apache License 2.0

Copyright

Copyright (c) 2018 TIS Inc.