Giter VIP home page Giter VIP logo

mqtt-postgres-k8s's Introduction

mqtt-postgres-k8s

This sample code shows how to deploy an application to the EnSaaS 4.0 environment and connect to the the database (Postgresql) and message broker (RabbitMQ) services provided by the platform.

  • Container Orchestration: Kubernetes
  • Package Manager: Helm

Table of Contents

Application Architecture

architecture


Ingress Layout

ingress


Quick Start

1. Downloading the Project

$ git clone [email protected]:WISE-PaaS/mqtt-postgres-k8s.git
$ cd mqtt-postgres-k8s/helm-chart

2. Installing a Release

First, make sure you are working in the EnSaaS 4.0 environment.

$ kubectl config get-contexts

Switch to the correct environment if you are not currently in the EnSaaS environment.

$ kubectl config use-context [CONTEXT]

Install the applicaiton to the platform.

$ helm install demo .

Show the list of installed applications.

$ helm ls

Now, you have completed the deployment, and your app is good to go!

3. Retrieving the URL of the Application

$ kubectl get ingress

In the output, you can find the hostname of the application.

$ kubectl get ing
NAME                     HOSTS                                              ADDRESS                      PORTS   AGE
demo-iot-home-dave-lee   iot-home-dave-lee.devspace.eks004.en.internal      10.0.9.4,10.0.9.5,10.0.9.6   80      108s

The naming convention for the HOSTS while you are deploying the app to EnSaaS. You can set up these required valus in your Helm Chart.

{Host}.{Namespace}.{ClusterName}.en.internal

From the HOSTS, you can derive the external URL with the following format:

https://{Host}-{Namespace}-{ClusterName}.sa.wise-paas.com

In this example, we can access the application by going to:

https://iot-home-dave-lee-devspace-eks004.sa.wise-paas.com


Customizing the Application

1. Building & Pushing the Images

$ cd server/
$ docker build {DockerHubAccount}/{ImageName}:{Tag} .
$ docker push {DockerHubAccount}/{ImageName}:{Tag}

$ cd ../iothub-mqtt/
$ docker build {DockerHubAccount}/{ImageName}:{Tag} .
$ docker push {DockerHubAccount}/{ImageName}:{Tag}

2. Configuring the Helm Chart

$ cd ../helm-chart/

Inside Chart.yaml, customize your Chart Name and Versions.

chart

The Chart Name and Chart Version will be displayed in the helm list as soon as you install a release.


Inside Values.yaml, you can tune the following options:

  • namespace

    Set this value according to the namespace that has been created in your workspace.

  • replicaCount

    Increase this value to scale out the application.

    values-1


  • repository

    Your DockerHub account

  • imageNmae & tag

    Change these values if you have built your own images.

  • resources

    Fine-tune resource usage according to your need.

    values-2


  • global.database.secretName

    Name of the secret that you will use for these deployments.

    Naming convention for the secret: {ChartName}-{Namespace}-secret

    {ChartName} is defined in the Chart.yaml inside the helm-chart directory. The example shown below has iot-home-k8s as the Chart name and devspace as the namespace.

  • global.url.host

    Naming convention for host: .{Namespace}.{ClusterName}.en.internal

    en.internal at the end is a fixed string. And also notice that there is dot (.) at the beginning of the host value. In the following example, once you install a helm release, this host will be combined with the ingress.hosts[0].host and become the external URL as iothome.devspace.eks004.sa.wise-paas.com. We can see that the en.internal has been replaced with sa.wise-paas.com.

    values-3


3. Installing a Release

As mentioned in the first section, install the release using helm install once you have finished your customized.

# Under helm-chart directory
$ helm install {ReleaseName} .

Upgrade & Rollback

One way to upgrade your release is to set up all the values that you want change in a file and then apply this file using the following command.

$ helm upgrade [RELEASE] [CHART] -f [YAML_FILE]

We can use the example file that has been included in this repository as a demonstration.

$ helm upgrade demo . -f newvalue.yaml

Inside newvalue.yaml:

deployParams:
  iothubMqtt:
    replicaCount: 2

This upgrade will scale out the application by adding another Pod that runs the mqtt container.

upgrade

Now, we can check what velues have been changed.

$ helm get values demo
USER-SUPPLIED VALUES:
deployParams:
  iothubMqtt:
    replicaCount: 2

You can also rollback the Release to the previous Revision using the following command.

Let's check the revision history first.

$ helm history demo
REVISION	UPDATED                 	STATUS    	CHART             	APP VERSION	DESCRIPTION
1       	Wed Feb 19 12:22:56 2020	superseded	iot-home-k8s-0.3.0	1.0.0      	Install complete
2       	Wed Feb 19 13:34:45 2020	superseded	iot-home-k8s-0.3.1	1.0.0      	Upgrade complete
3       	Wed Feb 19 15:21:20 2020	deployed  	iot-home-k8s-0.3.2	1.0.0      	Upgrade complete

Roll back to the revision No. 2.

$ helm rollback demo 2
Rollback was a success! Happy Helming!

Now, check the deployment again and we can see that the application has been scaled in by rolling back to the previous status.

rollback

mqtt-postgres-k8s's People

Contributors

allguitars avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.