Taxonomy Icon

Containers

IBM Watson Assistant is a robust platform that lets you collaborate on building conversational artificial intelligence (AI) solutions. Its graphical UI, powerful natural language processing and familiar developer features allow the rapid creation of anything from simple chatbots to complex enterprise-grade solutions for customer service and more.

Kubernetes is an open source project that can run in many different environments, from laptops to high-availability multi-node clusters, from public clouds to on-premises deployments, and from virtual machines to bare metal.

Why deployment of an app created with Watson Services is advantageous in Kubernetes

A managed Kubernetes offering delivers powerful tools, an intuitive user experience, and built-in security for rapid delivery of applications that you can bind to cloud services related to IBM Watson. As a certified Kubernetes provider, the IBM Cloud Kubernetes Service provides intelligent scheduling, self-healing, horizontal scaling, service discovery and load balancing, automated rollouts and rollbacks, and secret and configuration management. The Kubernetes Service also has advanced capabilities around simplified cluster management, container security and isolation policies, the ability to design your own cluster, and integrated operational tools for consistency in deployment.

This tutorial gives you step-by-step instructions for setting up your own instance of a chatbot that uses Watson services (the Cognitive Car Dashboard) and how to deploy it to the Kubernetes environment on IBM Cloud using the IBM Cloud Developer Tools command-line interface to streamline the deployment process.

Watson Assistant sample application

This Node.js app demonstrates the Watson Assistant service in a simple chat interface simulating a cognitive car dashboard.

Copy

What you’ll learn

  • How to create a Cognitive Car Dashboard app with the IBM Watson Assistant service
  • How to package an app as a Docker container
  • How to create your Kubernetes cluster on an IBM Cloud Kubernetes Service environment
  • How to deploy your Cognitive Car Dashboard app to an IBM Cloud Kubernetes Service cluster

Prerequisites

Before you begin, you’ll need:

Clone or download your Watson Assistant application

Note: The Watson Assistant sample app has been used in this tutorial. You can use the Watson Assistant Workspace of your choice.

git clone https://github.com/watson-developer-cloud/assistant-simple

Configure the application

  1. Log in to your IBM Cloud account.

  2. Create a Watson Workspace.

  3. Launch the tool.

  4. Click the Import workspace icon in the Watson Assistant service tool, and specify the location of the workspace JSON file in your local copy of the app project: <project_root>/training/car_workspace.json

    Copy

    Copy

  5. Ensure that you are in the working directory: cd assistant-simple.

  6. Create a .env file: cp .env.example .env.

  7. Open the .env file and add the environmental variables asked for in the file. You can get the Workspace ID by clicking View Details. Copy the Workspace ID and paste it in the .env file under Workspace ID.

    Copy

    Copy

  8. Click Show to view the Service Credentials. Copy the apikey value, or copy the username and password values if your service instance doesn’t provide an apikey. Also copy the url value. Paste these values in the .env file. Save the file and close it.

    Copy

Example .env file

# Environment variables
WORKSPACE_ID=55dc1ba5-dd1e-4cd7-b7a3-13aa39f5b60c
# You need to provide either username and password
ASSISTANT_USERNAME=4df4e0d9-7b70-4e8d-beb5-4008a3dfb45a
ASSISTANT_PASSWORD=ZZSHTWLuvJSo
# OR IAM API key and URL
ASSISTANT_IAM_APIKEY=
ASSISTANT_IAM_URL=
ASSISTANT_URL=https://gateway.watsonplatform.net/assistant/api

Deploy the application to the IBM Cloud Kubernetes Service

  1. Ensure that you are in the working directory: cd assistant-simple.

  2. Make sure that you are logged in to the IBM Cloud and IBM Cloud Container: ibmcloud login. For Single Sign-On, use ibmcloud login --sso.

  3. Log in to the Container Registry Service: ibmcloud cr login.

  4. Create a Dockerfile that is used to create the Docker image for both a local ibmcloud dev build/run and for a remote ibmcloud development deployment: vi Dockerfile.

    Note: You can use any cli commands you like to create the file. There is no extension to the file.

  5. Paste following code to the Dockerfile and save the changes.

    FROM node:6-alpine
    ADD . /app
    RUN cd /app; npm install
    
    ENV NODE_ENV production
    ENV PORT 8080
    EXPOSE 8080
    
    WORKDIR "/app"
    CMD [ "npm", "start" ]
    
  6. Install a Docker engine if you don’t have one.

  7. Determine whether you have the Docker engine running: docker version.

    You must check your installation if you get following error:

    ERRO[0005] failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial unix /var/run/docker.sock: connect: no such file or directory context canceled
    
  8. Find your container registry namespace by running: ibmcloud cr namespaces.

  9. If you don’t have a namespace, create one using: ibmcloud cr namespace-add <name>.

  10. Identify your Container Registry by running: ibmcloud cr info (for example, registry.ng.bluemix.net).

  11. Build and tag (-t) the Docker image by running the following command and replacing REGISTRY and NAMESPACE with the appropriate values.

    docker build . -t <REGISTRY>/<NAMESPACE>/myapp:v1.0.0` (Example: `docker build . -t registry.ng.bluemix.net/mynamespace/myapp:v1.0.0`)
    
  12. Push the docker image to your Container Registry on IBM Cloud: docker push <REGISTRY>/<NAMESPACE>/myapp:v1.0.0.

  13. Create a Kubernetes cluster (for more details, see Creating a Kubernetes cluster in IBM Cloud). Choose Cluster Type – Free, give a unique name to the cluster, and click Create Cluster.

    Copy

    It will take some time. It is ready to use if you see following:

    Copy

  14. Follow the instructions in the Access tab to set up your kubectl CLI.

  15. Make sure that you are in your working directory: cd assistant-simple.

  16. Create a folder called kubernetes: mkdir kubernetes.

  17. Create a deployment.yaml file: vi deployment.yaml, and copy and paste following code:

    Note : You must replace the name of your Watson Assistant app in the deployment.yaml file if you are using a different Watson Assistant app.

    # Update <REGISTRY> <NAMESPACE> values before use
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: assistant-simple
    labels:
      app: assistant-simple
    spec:
    replicas: 1
    selector:
      matchLabels:
        app: assistant-simple
    template:
      metadata:
        labels:
          app: assistant-simple
      spec:
        containers:
        - name: assistant-simple
          image: <REGISTRY>/<NAMESPACE>/myapp:v1.0.0
          ports:
          - containerPort: 8080
          imagePullPolicy: Always
    
  18. Create a deployment: kubectl create -f kubernetes/deployment.yaml.

  19. Create a service by using the Worker IP and NodePort: kubectl expose deployment assistant-simple --type NodePort --port 8080 --target-port 8080.

    Note Use your Watson Assistant app name instead of assistant-simple if you are using a different Watson Assistant app.

Access the application

  1. Verify that the status of pod is RUNNING: kubectl get pods -l app=assistant-simple.

    Note Use your Watson Assistant app name instead of assistant-simple if you are using a different Watson Assistant app.

    It should look like:

    NAME                                READY     STATUS    RESTARTS   AGE
    assistant-simple-58b5f4688f-twztt   1/1       Running   0          2m
    
  2. Access your chatbot application:

    1. Identify your Worker Public IP using ibmcloud cs workers YOUR_CLUSTER_NAME.
    2. Identify the Node Port using kubectl describe service assistant-simple.

      Note Use your Watson Assistant app name instead of assistant-simple if you are using a different Watson Assistant app.

    3. Access your application at http://<WORKER-PUBLIC-IP>:<NODE-PORT>/.

Clean up

Use the following command to clean up.

kubectl delete deployment,service -l app=assistant-simple

Conclusion

This tutorial walked you through the process of deploying a chatbot in the IBM Cloud Kubernetes Service environment. By combining Watson Assistant and the IBM Cloud Kubernetes Service, you can have 24/7 customer engagement for your teams. I recommend that you scale your Watson service application and make it more reliable by using at least three worker nodes in the IBM Cloud Kubernetes Service environment. I started with one, but having the extra nodes means that the app could handle the fluctuations in traffic. Starting from the beginning with high availability in mind is important.