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
$ git clone git@github.com:WISE-PaaS/mqtt-postgres-k8s.git
$ cd mqtt-postgres-k8s/helm-chart
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!
$ 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
$ 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}
$ cd ../helm-chart/
Inside Chart.yaml
, customize your Chart Name and Versions.
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.
-
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.
-
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 theChart.yaml
inside thehelm-chart
directory. The example shown below hasiot-home-k8s
as the Chart name anddevspace
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 thehost
value. In the following example, once you install a helm release, thishost
will be combined with theingress.hosts[0].host
and become the external URL asiothome.devspace.eks004.sa.wise-paas.com
. We can see that theen.internal
has been replaced withsa.wise-paas.com
.
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} .
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.
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.