< img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=3131724&fmt=gif" />

Create a Microservices-based App

With each microservice handling a single part of the app's functionality, an app can be divided into different components. These components have their own responsibilities and limitations, independent from each other. In KubeSphere, this kind of app is called Composed App, which can be built through newly created Services or existing Services.

This tutorial demonstrates how to create a microservices-based app Bookinfo, which is composed of four Services, and set a customized domain name to access the app.

Prerequisites

  • You need to create a workspace, a project, and a user (project-regular) for this tutorial. The user needs to be invited to the project with the operator role. For more information, see Create Workspaces, Projects, Users and Roles.
  • project-admin needs to set the project gateway so that project-regular can define a domain name when creating the app.

Create Microservices that Compose an App

  1. Log in to the web console of KubeSphere and navigate to Apps in Application Workloads of your project. On the Composed Apps tab, click Create.

  2. Set a name for the app (for example, bookinfo) and click Next.

  3. On the Services page, you need to create microservices that compose the app. Click Create Service and select Stateless Service.

  4. Set a name for the Service (e.g productpage) and click Next.

    Note

    You can create a Service on the dashboard directly or enable Edit YAML in the upper-right corner to edit the YAML file.
  5. Click Add Container under Containers and enter kubesphere/examples-bookinfo-productpage-v1:1.13.0 in the search box to use the Docker Hub image.

    Note

    You must press Enter in your keyboard after you enter the image name.
  6. Click Use Default Ports. For more information about image settings, see Pod Settings. Click in the lower-right corner and Next to continue.

  7. On the Volume Settings page, add a volume or click Next to continue.

  8. Click Create on the Advanced Settings page.

  9. Similarly, add the other three microservices for the app. Here is the image information:

    ServiceNameImage
    Statelessdetailskubesphere/examples-bookinfo-details-v1:1.13.0
    Statelessreviewskubesphere/examples-bookinfo-reviews-v1:1.13.0
    Statelessratingskubesphere/examples-bookinfo-ratings-v1:1.13.0
  10. When you finish adding microservices, click Next.

  11. On the Route Settings page, click Add Routing Rule. On the Specify Domain tab, set a domain name for your app (for example, demo.bookinfo) and select HTTP in the Protocol field. For Paths, select the Service productpage and port 9080. Click OK to continue.

    Note

    The button Add Routing Rule is not visible if the project gateway is not set.
  12. You can add more rules or click Create to finish the process.

  13. Wait for your app to reach the Ready status.

Access the App

  1. As you set a domain name for the app, you need to add an entry in the hosts (/etc/hosts) file. For example, add the IP address and hostname as below:

    192.168.0.9 demo.bookinfo
    

    Note

    You must add your own IP address and hostname.
  2. In Composed Apps, click the app you just created.

  3. In Resource Status, click Access Service under Routes to access the app.

    Note

    Make sure you open the port in your security group.
  4. Click Normal user and Test user respectively to see other Services.

Receive the latest news, articles and updates from KubeSphere


Thanks for the feedback. If you have a specific question about how to use KubeSphere, ask it on Slack. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.