Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Serverless and Kubernetes Workshop on IBM Cloud


Published on

Workshop for Kubernetes and Serverless on IBM Cloud. Use templates to have demo code on Openwhisk and Kubernetes mit Devops, Cloudant NoSQL and Watson Services

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Serverless and Kubernetes Workshop on IBM Cloud

  1. 1. Kubernetes And Serverless Computing Workshop With IBM Cloud Kubernetes and Serverless Workshop with IBM Cloud 1 / 39
  2. 2. Administrative Stuff before we start 3 Create account 3 Applying the voucher 5 Creating a Kubernetes Cluster 7 Serverless Computing 9 Quickstart “Hello World” 10 Seeing Serverless Code 10 REST access to a function 11 Postman 13 Web access to a function 14 A more complex example - Cloudant Events 15 Create a database 16 Gettings Database credentials 17 Create a database 19 Deploy the template 20 Function code 20 Add a document to the database 21 Monitor serverless computing 22 Kubernetes 23 Nodes 23 Web Apps 24 Python Watson Assistant Basic 25 Deploy project 25 Toolchain 27 See the demo in action 28 Kubernetes Dashboard 29 Kubernetes yaml file 30 Orion - the build-in editor 32 Repositor code checkin 34 See your application in action 35 The Watson Assistant 36 Intents 37 Entities 38 Conversation Flow 39 Kubernetes and Serverless Workshop with IBM Cloud 2 / 39
  3. 3. Administrative Stuff before we start Hello and welcome to a journey into Serverless, Kubernetes, Devops, Watson Service and hopefully fun. First of all, this tutorial is not meant to be done in one session, so don’t worry if you don’t make it in the workshop itself. So let’s get ready to rock and roll. Create account We start with signing up for an account at ​ Sign up with your Email address, name and a very secure password. Kubernetes and Serverless Workshop with IBM Cloud 3 / 39
  4. 4. After clicking create IBM creates a new account for you. IBM will send you an email as shown below, please click the containing link. After clicking the link in your email your IBM ID and therefore the IBM Cloud account is ready to be used. Yeah! Kubernetes and Serverless Workshop with IBM Cloud 4 / 39
  5. 5. Welcome to the world of IBM Cloud aka Bluemix. This is the main dashboard. Whenever you are lost somewhere just press the IBM Cloud button on top left to come back to this dashboard. The newly created account is a so called free account. Forever free without expiration but with a limited amount of possibilities. So first we need to add a voucher to upgrade to a normal account. This can be done in the Manage / Billing and Usage menu. Applying the voucher Kubernetes and Serverless Workshop with IBM Cloud 5 / 39
  6. 6. Under Billing / Feature Code please add the voucher code from IBM. Sorry if you have to type it in and can not copy-paste it, it’s really long. After doing so you will get this upgrade information box. Very important here, the upgrade to the trial account which we will need for Kubernetes. Kubernetes and Serverless Workshop with IBM Cloud 6 / 39
  7. 7. Let’s go back the the dashboard and press the “hamburger” menu icon on the left top side. This will bring us to the All Categories Menu. For example here to the Watson Services part where you can try the IBM Watson Services for free, give it try later on. Creating a Kubernetes Cluster As creating a Kubernetes Cluster in Bluemix takes some time we do it first before we continue to work with the serverless part. The cluster management can be found under “Containers”. Please press the “Containers in Kubernetes Clusters”. This will bring you to a list of available features. For now we just press the “Create” button. Kubernetes and Serverless Workshop with IBM Cloud 7 / 39
  8. 8. Here we can see the kind of Kubernetes cluster we can create. With the trial account we can only configure one free cluster. Let’s select the free cluster now. And press “Create Cluster”. This will start the Kubernetes management system and one worker node. IBM Cloud is doing now all the magic which is necessary to create a Kubernetes cluster in the background. Under Overview we can see the Cluster is in “Deploying” state and has one pending node. Kubernetes and Serverless Workshop with IBM Cloud 8 / 39
  9. 9. Serverless Computing Let’s give the IBM Cloud system some time to setup the Kubernetes cluster while we work on the serverless part. If you don’t see the menu on the left side just press the “Hamburg” menu button next to IBM cloud again. Then press “functions” or as marketing likes to call it “serverless computing”. Serverless consists of actions (functions written in python, javascript or even C or C++ inside docker containers) which are orchestrated in sequences and triggered by external events like e.g. DB entries, IoT or slack chats. We will see how all this works now and try it with two examples. Beside using the command line tools (CLI) there is a very nice way to try out IBM functions or openwhisk just in a browser window. So please press “start creating”. Kubernetes and Serverless Workshop with IBM Cloud 9 / 39
  10. 10. Quickstart “Hello World” For now we use the Quickstart Template to test out a very simple “Hello World”. Please press the “Hello World” template. Seeing Serverless Code This brings us to the configuration menu. Here you can change the language for the template and give the package a nice name. It doesn't matter which language you choose, as this is just a hello world and it’s available in many different languages, the concept is always the same. Please select your favourite one and see how the functions should be written in a very simple case of hello world. The following picture shows the javascript code. As you can see each function is called with a json object as parameter and returns one json object. Kubernetes and Serverless Workshop with IBM Cloud 10 / 39
  11. 11. As you can see in the code the function checks for the key “name” in the input json and returns a greeting with the name if it is in the json dictionary or just “hello stranger”. Gratulation you just deployed your first serverless application. Well a very small one but it’s already deployed in the IBM cloud and ready to be used globally. Now let’s see for the other menu parts in the serverless menu. Under runtime the timeout and the maximum amount of RAM used by this function can be configured. As serverless computing is charged my TIME*RAM it can become really handy to check here for the upper thresholds in order to minimize the cost in case a function does not end or consumes all available RAM. REST access to a function Now we have a function deployed in the cloud but how can we trigger / access this function to do some useful stuff for us. “Endpoints” lets you configure REST API endpoints or even very simple web access in case you want your application to be public accessible. Kubernetes and Serverless Workshop with IBM Cloud 11 / 39
  12. 12. First is the REST API endpoint. As this one is secured by an API-KEY we first need to configure this API-KEY by pressing the link API-KEY. For now please copy this KEY by pressing the copy icon to your clipboard. The API-KEY consists of two parts, separated by “:”. The first part can we seen as a username, while the second part is the password. An example API-KEY looks like this: Kubernetes and Serverless Workshop with IBM Cloud 12 / 39
  13. 13. Postman Testing a REST api can be done without any computer language by a very handy tool called POSTMAN (​​). If you want you can install it now for the REST api test, or just take a look at the screenshots for now. Select POST as connection type and copy the URL from IBM Cloud into it. The API-KEY is necessary for the Authorization part. As described the API-KEY consists of username and password divided by “:”. Please copy the key parts into the Username and Password fields. This is everything we need to do to access our serverless function. Press send to see the result. The function itself looks for the “name” in the calling json so if we want to try this part of the serverless function we can click Body, select raw, JSON(application/json) and add this very simple json file “{“name”:”ansi”}. Then press the send button to see the result of our call. Kubernetes and Serverless Workshop with IBM Cloud 13 / 39
  14. 14. The response is a complex json file will all kind of runtime environment and statistic information. Very important beside the response/result value is also the start and end time. One key feature of serverless computing is the response time. These functions are loaded and executed very fast without costing anything while not active. So you can have thousands of functions waiting for being called without paying a single cent. Only when an event is triggered the function is called and you pay by TIME*RAM which can be very very low. As a technical background information you need to know the function itself is not actively waiting for your call. It’s stored in a database and when you call it the first time the function is pulled from the database and wrapped in the runtime environment before it is expected. This can take up to 300 hundred milliseconds when it’s code like python or javascript. When it is a docker container for java or C++ or even GO it can take some time to fetch the docker container out of a repository. But this is only the first call, all following calls are started within some milliseconds. When a function is not called for several minutes the runtime is removed and the following later call will take again some time. Web access to a function Using the API-KEY and the full REST interface is necessary when you want to use the function with your program. Maybe you place some parts of your program in Kubernetes some other parts in Cloud Foundry and other parts in Openwhisk. Is this case the access need to be controlled. But sometimes you want to expose your function to the web itself without password. In this case you can activate the “Enable as Web Action”. In this case Openwhisk provides an URL which can be called without any password directly from a webpage. E.g. a Formular. Try the Public URL in your browser. Kubernetes and Serverless Workshop with IBM Cloud 14 / 39
  15. 15. A more complex example - Cloudant Events Now let’s do something more complex and meaningfull. For example monitor a database and calculate some values whenever there is a new document or someone changed a document. Let’s go back to the “Hamburger” menu and press Functions and again the “Quickstart Templates”. This time we select “Cloudant Events” as the template. As you can see this time it is more complex and there is an action sequence involved. The first one reads data from a database and hands it over to the second one. Kubernetes and Serverless Workshop with IBM Cloud 15 / 39
  16. 16. Beside the action sequence there is also a trigger involved. Listening to the cloudant database for changes and starts the sequence in case of changes. Create a database As we want to work with a database we need to create one first. This can be done very easily in bluemix. Select the “Create a new instance” and you will see this popup. The “Let’s go” button brings us to the cloudant service request menu. Make sure you select the right location where you have done everything else before and press create. Kubernetes and Serverless Workshop with IBM Cloud 16 / 39
  17. 17. Now we have a NoSQL database up and running. What we need now are the credentials to access this database. This can be done in the “Service credentials” on the left side. Gettings Database credentials On a newly created database there are no external credentials configured. So let’s create one by pressing “New credentials”. Kubernetes and Serverless Workshop with IBM Cloud 17 / 39
  18. 18. Nothing special to configure so just press “Add”. Now we have REST credentials for the cloudant database. Press the little arrow down next to “View Credentials”. These credentials we will need later on for the trigger in your function. Beside the access credentials we also need a database configured. This can be done with the Cloudant web interface. Press the “Manage” menu on the left side and then the “LAUNCH” on the right side. This brings is to the cloudant dashboard. We can modify databases, see and modify data aso. For now we just want to add a new database. Kubernetes and Serverless Workshop with IBM Cloud 18 / 39
  19. 19. Create a database This can be done on the top right side with “Create Database”. This name is also important for the trigger configuration. Back to the function window in your browser. Press “OK” on the popup. Kubernetes and Serverless Workshop with IBM Cloud 19 / 39
  20. 20. Deploy the template Now we can add the Username, Password, Host from the credentials window and also the database name we created. “Deploy” will install the trigger, actions and also the sequence. Under “Sequence” we can now see, modify and trigger our sequence. Function code But first let’s have a look at the code itself and find out what the “Process-Change” is doing. As we can see it searches for “name” and “color” fields in the database document and returns a message containing both words. So let’s create a new database document containing these keywords. Kubernetes and Serverless Workshop with IBM Cloud 20 / 39
  21. 21. Add a document to the database So let’s create a new database document with these words and see what happens. Please go back to your Cloudant dashboard window and press the Database Symbol on the left side. (The stacked disks.) And then select your database. Top right there is the “Create Document” button. NoSQL databases work with json documents. So all we need to do is to add at least two key-value entries like these to the database. Please make sure you have commas behind each line, except the last one. Kubernetes and Serverless Workshop with IBM Cloud 21 / 39
  22. 22. After pressing “Create Document” we will see the document added to our database. Monitor serverless computing But back to the function window where we hopefully see the trigger and sequence in action. This can be done on the left menu with “Monitor”. Under activity log there is hopefully an entry, telling you the created message with the name and color included. This was the function aka serverless part of the workshop. Now for a simple demo deploy in kubernetes. Kubernetes and Serverless Workshop with IBM Cloud 22 / 39
  23. 23. Kubernetes OK, let’s dive right into Kubernetes. Click the IBM Cloud logo in order to get back to the main dashboard. Here we see now the kubernetes cluster with 1 node. Click on your clustername. Nodes As we can see now in the overview the cluster is ready and the node is ready too. Under worker nodes you can get more information on the workers, add more worker nodes or delete worker nodes. Depending on your workload you can manage your servers here. Kubernetes and Serverless Workshop with IBM Cloud 23 / 39
  24. 24. Web Apps Like we saw in the serverless part there is an easy way to install templates and already existing demo approcations. Please press the “Hamburger” menu and select “Web Apps”. This brings us to the Cloud App Service Center. Beside information on the command line interface there is also the Web part. A perfect place to deploy and manage complex applications. Please press the “Get Started” button there. Kubernetes and Serverless Workshop with IBM Cloud 24 / 39
  25. 25. Python Watson Assistant Basic Now you see a huge variation of already existing applications. A great start from “Hello World” to already complex applications. For now we select the “Python Watson Assistant Basic” application. As we configure now a complete project with source code, deployment pipeline and services we need to provide a project name and also a hostname plus domain. Please press “Create Project”. Deploy project Now our project and the requested services are configured. Let’s deploy the project now on the cloud by pressing “Deploy to Cloud”. Kubernetes and Serverless Workshop with IBM Cloud 25 / 39
  26. 26. Here we can choose between a kubernetes and cloud foundry installation. So let’s select our cluster and press “Create”. Now we have the project configured and a deployment pipeline for our project, including a toolchain for change management and automatic deploy. Press the “view toolchain” in order to see how the source code is managed and the automatic deploy works. Kubernetes and Serverless Workshop with IBM Cloud 26 / 39
  27. 27. Toolchain This is our toolchain. IBM Cloud has a build in github including git source management and Issue tracking. For now let’s concentrate on the deliver part of the toolchain. Simply press the “Deliver Pipeline” icon. The deployment has 2 steps. The first one takes care of getting the source code and building the docker container and the second stage is responsible for deploying the container on the kubernetes cluster. Kubernetes and Serverless Workshop with IBM Cloud 27 / 39
  28. 28. In order to get the URL for our active project we need to have a look at the logfiles in the “Deploy Stage”. Please press “View logs and history”. Scroll down to the very end and check for the URL. In this case See the demo in action If you open this URL you can see your installation of a very simple chat bot application using Watson services. On the left side you can chat with your car-AI and on the right side you see the JSON object which are exchanged between your app and the Watson conversation service. Kubernetes and Serverless Workshop with IBM Cloud 28 / 39
  29. 29. Kubernetes Dashboard Now let’s see how the application is installed on kubernetes. Let’s go back to the main dashboard and then to your cluster. On the top right is the “Kubernetes Dashboard” button. This opens a new window the the official kubernetes dashboard. Here you can get all information about your cluster, the installed applications, the services within kube and a lot of other stuff. Kubernetes and Serverless Workshop with IBM Cloud 29 / 39
  30. 30. For now we concentrate on the installed application. This is managed in a “Pod”. Kubernetes yaml file If you want to see the configuration and the deployment yaml files there is a “Edit” button on top right of your dashboard. Kubernetes and Serverless Workshop with IBM Cloud 30 / 39
  31. 31. Now let’s see how easy it is to chance the application code and see the deployment pipeline in action. First we need to go back to our DevOps pipeline. The easiest path is via the “Hamburger” menu, then DepOps, ToolChains and then your project. Kubernetes and Serverless Workshop with IBM Cloud 31 / 39
  32. 32. Orion - the build-in editor This time we use the web based online Editor “Orion” This brings us directly to our source code. The landing page just show you the file of your project. What we want to do now is to chance one line in the CSS file. This file can be found by opening the source code tree on the left side. Kubernetes and Serverless Workshop with IBM Cloud 32 / 39
  33. 33. The CSS file is located at public / css. Please change the line 118 in app.css “color: “ to whatever color you like. Kubernetes and Serverless Workshop with IBM Cloud 33 / 39
  34. 34. Repositor code checkin Now we changed to source code and need to check it in into our repository. The build in version manager can be found on the left side. Directly under the edit icon. First we need to commit our change by adding a comment and pressing the “Commit” button and then we can push our changes to the repository with the sync button on the left side. After syncing the repository manager should report “Nothing to commit” Kubernetes and Serverless Workshop with IBM Cloud 34 / 39
  35. 35. Now back to our deployment pipeline. Here we see the first stage has picked up the changes and rebuild the container. See your application in action As soon as the second stage is finished we can reload our application in the other browser window. No Watsons anser has changed from white to your selected color. Kubernetes and Serverless Workshop with IBM Cloud 35 / 39
  36. 36. Now as a final step, let’s have a look at the underlying watson service. If you open the main IBM cloud dashboard you see there is a new service called “Watson Assistant”, press it in order to open the detailed information page. At the Manage page you see the “Open tool” button. Please press it. The Watson Assistant The Watson Assistant is a very powerful but also complex service. Just let’s have a very very short impression. Please press the Workspaces button to see the existing workspaces. Kubernetes and Serverless Workshop with IBM Cloud 36 / 39
  37. 37. The Workspace we used is the “Car Dashboard sample”. Intents Every Conversation consists if 3 parts. The First one is the “Intents”, basically what is the intention a conversation has. Kubernetes and Serverless Workshop with IBM Cloud 37 / 39
  38. 38. Entities The second one are the entities which we may encounter in our conversation. Kubernetes and Serverless Workshop with IBM Cloud 38 / 39
  39. 39. Conversation Flow And the last one is the conversation flow. For example if we ask to switch on music the system does not know what kind of music so the conversation service ask for the genre before the underlying business code can switch on the radio. This is the end of this tutorial. Ufffffff. I hope you had some fun and learned how to use Kubernetes and Serverless in the IBM Cloud. For sure this was a rough ride and only on the surface but I can be used as a starter to a fantastic journey. If you have more questions the documentation which you can always find on the top right corner is very detailed and explains both the high level part but also the low level API access parts. Kubernetes and Serverless Workshop with IBM Cloud 39 / 39