ballerina/cloud

Overview

This modules provides the capabilities to generate the cloud artifacts for Ballerina programs.

This module generates the Kubernetes and Docker artifacts required to deploy a Ballerina program in the cloud.

Supports following artifact generation:

  • Kubernetes deployment
  • Kubernetes service
  • Kubernetes liveness probe
  • Kubernetes readiness probe
  • Kubernetes config map
  • Kubernetes horizontal pod autoscaler
  • Docker image
  • Dockerfile

Docker artifact generation

Build the Ballerina Program with --cloud=docker option to generate Docker artifacts (Dockerfile and Docker image).

1$> bal build --cloud=docker
2Compiling source
3 hello/hello:0.0.1
4
5Creating balas
6 target/bala/hello-2020r2-any-0.0.1.bala
7
8Running Tests
9
10 hello/hello:0.0.1
11 No tests found
12
13
14Generating executables
15 target/bin/hello.jar
16
17Generating artifacts...
18
19 @kubernetes:Docker - complete 2/2
20
21 Execute the below command to run the generated docker image:
22 docker run -d -p 9090:9090 anuruddhal/hello-api:sample8
23
24 target/bin/hello-0.0.1.jar

Kubernetes artifact generation

Build the Ballerina Program with --cloud=k8s option to generate Docker and Kubernetes artifacts.

1$> bal build --cloud=k8s
2Compiling source
3 hello/hello:0.0.1
4
5Creating balas
6 target/bala/hello-2020r2-any-0.0.1.bala
7
8Running Tests
9
10 hello/hello:0.0.1
11 No tests found
12
13
14Generating executables
15 target/bin/hello.jar
16
17Generating artifacts...
18
19 @kubernetes:Service - complete 1/1
20 @kubernetes:Deployment - complete 1/1
21 @kubernetes:HPA - complete 1/1
22 @kubernetes:Docker - complete 2/2
23
24 Execute the below command to deploy the Kubernetes artifacts:
25 kubectl apply -f /Users/anuruddha/workspace/ballerinax/module-ballerina-c2c/samples/sample2/target/kubernetes/hello
26
27 Execute the below command to access service via NodePort:
28 kubectl expose deployment hello-hello-0-0-deployment --type=NodePort --name=hello-hello-0-0-svc-local

Cloud.toml

The configuration file to be used to override the default values generated by code to cloud. The Cloud.toml file is completely optional and only has to specify the values that need to be overridden. If the value is not specified for a certain field, the compiler will take the default value. All the supported properties can be found here.

Records

[2]

ScheduleConfig

Cron Job Schedule Configuration.

TaskConfig

Task Configuration.

Annotations

[2]

Expose

@cloud:Expose annotation marks a port that has to be exposed in a custom listener initializer.

Task

@cloud:Task annotation to configure cron job.