Nidhi Shah | Published November 1, 2018
Artificial intelligenceContainersConversationDeep LearningMachine Learning
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.
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.
This Node.js app demonstrates the Watson Assistant service in a simple chat interface simulating a cognitive car dashboard.
Before you begin, you’ll need:
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
Log in to your IBM Cloud account.
Create a Watson Workspace.
Launch the tool.
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
Ensure that you are in the working directory: cd assistant-simple.
Create a .env file: cp .env.example .env.
cp .env.example .env
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.
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.
# Environment variables
# You need to provide either username and password
# OR IAM API key and URL
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.
ibmcloud login --sso
Log in to the Container Registry Service: ibmcloud cr login.
ibmcloud cr login
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.
Paste following code to the Dockerfile and save the changes.
ADD . /app
RUN cd /app; npm install
ENV NODE_ENV production
ENV PORT 8080
CMD [ "npm", "start" ]
Install a Docker engine if you don’t have one.
Determine whether you have the Docker engine running: docker version.
You must check your installation if you get following error:
ERRO 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
Find your container registry namespace by running: ibmcloud cr namespaces.
ibmcloud cr namespaces
If you don’t have a namespace, create one using: ibmcloud cr namespace-add <name>.
ibmcloud cr namespace-add <name>
Identify your Container Registry by running: ibmcloud cr info (for example, registry.ng.bluemix.net).
ibmcloud cr info
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`)
Push the docker image to your Container Registry on IBM Cloud: docker push <REGISTRY>/<NAMESPACE>/myapp:v1.0.0.
docker push <REGISTRY>/<NAMESPACE>/myapp:v1.0.0
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.
It will take some time. It is ready to use if you see following:
Follow the instructions in the Access tab to set up your kubectl CLI.
Make sure that you are in your working directory: cd assistant-simple.
Create a folder called kubernetes: mkdir kubernetes.
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
- name: assistant-simple
- containerPort: 8080
Create a deployment: kubectl create -f kubernetes/deployment.yaml.
kubectl create -f kubernetes/deployment.yaml
Create a service by using the Worker IP and NodePort: kubectl expose deployment assistant-simple --type NodePort --port 8080 --target-port 8080.
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.
Verify that the status of pod is RUNNING: kubectl get pods -l app=assistant-simple.
kubectl get pods -l app=assistant-simple
It should look like:
NAME READY STATUS RESTARTS AGE
assistant-simple-58b5f4688f-twztt 1/1 Running 0 2m
Access your chatbot application:
ibmcloud cs workers YOUR_CLUSTER_NAME
Identify the Node Port using kubectl describe service assistant-simple.
kubectl describe service assistant-simple
Access your application at http://<WORKER-PUBLIC-IP>:<NODE-PORT>/.
Use the following command to clean up.
kubectl delete deployment,service -l app=assistant-simple
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.
Set up both Kubeflow and IBM Cloud Private to work together in a private cloud environment where your data is…
Get the Code »
Back to top