import ballerina/config;
import ballerina/http;
import ballerina/log;
import ballerina/kubernetes;
@kubernetes:Service {
serviceType: "NodePort"
}
@kubernetes:Ingress {
hostname: "abc.com"
}
listener http:Listener helloWorldEP = new(9090, config = {
secureSocket: {
keyStore: {
path: "./security/ballerinaKeystore.p12",
password: "ballerina"
},
trustStore: {
path: "./security/ballerinaTruststore.p12",
password: "ballerina"
}
}
});
@kubernetes:ConfigMap {
conf: "./ballerina.conf"
}
@kubernetes:Deployment {
livenessProbe: true,
image: "kubernetes:v.1.0"
}
@http:ServiceConfig {
basePath: "/helloWorld"
}
service helloWorld on helloWorldEP {
@http:ResourceConfig {
methods: ["GET"],
path: "/config/{user}"
}
resource function getConfig(http:Caller outboundEP, http:Request request, string user) {
string userId = getConfigValue(user, "userid");
string groups = getConfigValue(user, "groups");
json payload = {
userId: userId,
groups: groups
};
var responseResult = outboundEP->respond(payload);
if (responseResult is error) {
error err = responseResult;
log:printError("Error sending response", err);
}
}
}function getConfigValue(string instanceId, string property) returns (string) {
string key = <@untainted string> (instanceId + "." + property);
return config:getAsString(key, "Invalid User");
}# Create a `ballerina.conf` file with the following content in the same directory, which contains the kubernetes_deployment.bal file.
[john]
userid="john@ballerina.com"
groups="apim,esb"
[jane]
userid="jane3@ballerina.com"
groups="esb"
Kubernetes DeploymentBallerina supports generating Kubernetes artifacts based on annotations.
A single Ballerina module is mapped to a single Kubernetes deployment.
Minikube or Docker for Mac/Windows should be configured and
Kubernetes should be enabled to run the example.
This example deploys an HTTPS service, which retrieves values from a config file to Kubernetes.
Before running the sample, create a directory named |
|
|
|
Add the |
|
Service type is |
|
Add the |
|
Hostname of the service is |
|
Ballerina automatically creates Kubernetes secrets for the keystore and truststore when the |
|
Add the |
|
Path to the ballerina.conf file.
If a releative path is provided, the path should be releative to where the |
|
Add the |
|
Enable Kubernetes liveness probe to this service. |
|
Generate a Docker image with the name |
|
If you are using minikube, uncomment and change the following values accordingly.
//dockerHost:“tcp:// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|