In this scenario, we will deploy Flightassist to use a function that queries the necessary weather data. This shows how you could implement simple microservices with OpenWhisk. This approach replaces containers with OpenWhisk actions to save space and runtime memory in your cluster. Thanks to OpenWhisk built-in system packages, which includes a weather API, we don't even have to write our own action to implement the weather forecast lookup.
First, follow the Kubernetes Cluster Tutorial to create your own cluster on Bluemix.
Then, install the container registry plugin for Bluemix CLI.
bx plugin install container-registry -r BluemixNext, build your own docker images and push them to your own bluemix container registry.
You may skip these steps through deploying the secrets if you performed the Flightassist microservices deployment on Kubernetes or Istio scenarios
Replace
<namespace>with your own namespace, you can view your namespace by runningbx cr namespacesIf you have an unauthorized error, run
bx cr loginto authorized your container-registry.
docker build -f main_application/Dockerfile.local -t registry.ng.bluemix.net/<namespace>/flightassist main_application
docker build -f flightassist-weather/Dockerfile.alpine -t registry.ng.bluemix.net/<namespace>/weather-service flightassist-weather
docker push registry.ng.bluemix.net/<namespace>/flightassist
docker push registry.ng.bluemix.net/<namespace>/weather-serviceThen, you need to run the following commands to bind your Cloudant and Weather Insights services to your clusters.
bx cs cluster-service-bind {your-cluster-name} default mycloudant
bx cs cluster-service-bind {your-cluster-name} default myweatherinsightsNext, create secret to give FlightStats and TripIt API credentials for Flightassist. Modify the secret.yaml file with flightstats-app-id, flightstats-app-key, tripit-api-key, and tripit-api-secret.
Now, run the following commands to deploy the secret
kubectl create -f secret.yamlNote : you need to delete all the services and deployments from any previous scenarios.
kubectl delete -f flightassist.yaml
Then, install OpenWhisk CLI and Mark down its credentials.
Next, edit flightassist_serverless.yaml and replace the <namespace> with your own namespace, <your-app-end-point-url> with your node ip and nodeport, and <your-openwhisk-auth> with your OpenWhisk authentication. You can run wsk property get --auth | awk '{print $3}' to view your OpenWhisk authentication.
Now, let's deploy the new Flightassist app with serverless capability
kubectl create -f flightassist_serverless.yamlCongratulations, now your Flightassist application should be running on http://<your_node_ip>:30080. Also, you can learn about How to Use Flightassist and start testing your application.
In this example, the weather microservice in the Flightassist app is a perfect use case to convert it into a function on OpenWhisk. It is an event-triggered app, a stateless app, there are no sessions to manage, don’t require persistence, and performs a simple logical step. Many microservices, which don’t need to be long running applications or tasks can easily, be converted into serverless functions. This essentially gives you benefits like scaling etc., as well as cost benefits that you pay for infrastructure only when the application is used.
| File | Description |
|---|---|
| flightassist.js | Main application, start the express web server and calling the major AJAX functions |
| weather.js | Trigger actions in OpenWhisk to get the weather information |
| All JavaScript files (main_application/*.js) | The implementation of the flightstats and tripIt information, shared by all deployment options |
| package.json | List the packages required by the application |
| Dockerfile.local | Description of the Docker image |
| flightassist_serverless.yaml and secret.yaml | Specification file for the deployment of the service and secret in Kubernetes |