项目作者: IBM
项目描述 :
A kubernetes assistant which can manage your kubernetes clusters on IBM Cloud through voice
高级语言: Java
项目地址: git://github.com/IBM/kubernetes-speech-assistant.git
Talk to an app that can create and manage your Kubernetes instances
A Kubernetes Assistant that can manage your Kubernetes clusters on IBM Cloud through voice
Watch the video to check out a demo of the application.
Imagine being away from your computer when you realize you need to deploy a back end on a Kubernetes cluster that you have not yet provisioned. Knowing that provisioning a cluster could take several minutes after selecting the right configuration for your task, you visualize sitting in front of your computer staring idly at the screen, waiting for the cluster to be initialized and wishing that you could start work immediately.
Not in my world!
This developer code pattern demonstrates a Kubernetes speech assistant application for an Android mobile device. You can simply talk on your phone in natural language to provision, view, and manage your Kubernetes clusters without having to do it manually on the cloud interface.
The pattern showcases an Android app that mobile device users interact with and a Node.js back-end server that holds the application logic and talks to the IBM Cloud Kubernetes Service. The pattern demonstrates use of the IBM Identity and Access Management using the OpenID Connect specifications for a native application. It also showcases Watson Assistant to understand the natural language spoken by the mobile users, holding the context of the speech and converting the speakers’ intent into executable Kubernetes commands that are run on IBM Cloud.
In this code pattern, you learn the following skills:
- Create an Android application connected with the OpenID Connect specifications for IBM Identity and Access Management.
- Develop a Node.js server using Express.js, which interfaces with the Watson Assistant and the IBM Cloud Kubernetes Service.
- Set up Watson Assistant to create intents, entities, and a dialog flow.
- Convert speech to text and text to speech, natively for an Android application.
- Manage OpenID Connect authorization tokens on an Android application.
- Deploy a Node.js back-end server on the IBM Cloud Kubernetes Service.
Note: This codebase has two branches:
- Branch
master
showcases using IAM with API-KEY - Branch
using-iam-custom-ui
showcases using IAM with custom UI (This branch is not recommended for non-IBM developers as IAM currently doesn’t support creating credentials for non-IBM developers)
Architecture flow

- The user triggers a login into their IBM Cloud accounts on the Android App, if not previously setup.
- They are redirected to the IBM Cloud login page on their phone browsers, using the IBM IAM OpenID Connect Protocol.
- After successful authentication, a request is initiated to get a generic IAM token.
- The request sends the Authorization Code retrieved from Step 2 to the IBM IAM OpenID Connect Protocol to get the generic IAM token.
- A request is initiated to get the list of accounts associated with the cloud login.
- The request sends the generic IAM access token to the IBM Account Management API to retrieve the list of accounts associated with the user’s cloud login. The user selects an account from the list.
- A request is initiated to get an IAM token for the selected account.
- The request sends the generic IAM refresh token and the selected account ID to the IBM IAM OpenID Connect Protocol to retrieve an IAM token linked to the selected cloud account.
- The IAM Authorization Token object is persisted on the user’s device for future use, until expiration.
- A request is initiated to get the list of resource groups for the selected account.
- The request sends the account specific IAM access token to the IBM Resource Controller API to retrieve the list of resource groups associated with the account. The user selects a resource group from the list.
- A request is initiated to get a Watson Assistant session.
- The request talks to the Watson Assistant API SDK through the NodeJS server to get a new assitant session.
- The Android application setup is completed and the view is changed so that the user can start talking with the applicaton.
- The user sends a speech command to the application, by clicking the mic button and talking.
- The speech is converted to text using the native Android speech-2-text converter.
- A fresh IAM token request is issued using the previous IAM refresh token if the IAM access token has reached expiration.
- The fresh IAM access token/non-expired IAM access token, along with the user text input is sent to the NodeJS backend server on hosted on a Kubernetes cluster on the IBM cloud.
- The user text input is sent to the Watson Assistant to extract knowledge around the intent of the text and the different entities present.
- If the context for the user input is complete and all knowledge required to execute the Kubernetes command is obtained, a request is sent to the Kubernetes service API on IBM Cloud along with the user IAM access token and other parameters, to execute the command.
- The result of the executed command/a follow up question to get further details around the user request is sent to the Android application.
- The text received by the application is converted to speech by using the native Android text-2-speech converter.
- The speech is relayed to the user to continue the conversation.
Included components
- IBM Watson Assistant Watson Assistant lets you build conversational interfaces into any application, device, or channel.
- IBM Cloud Kubernetes Service gcreates a cluster of compute hosts and deploys highly available containers. A Kubernetes cluster lets you securely manage the resources that you need to quickly deploy, update, and scale applications.
- IBM Identity and Access Management Explore silent identity and access management solutions for today’s hybrid environments.
Featured technologies
- Node.js is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code.
- Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
- Axios Promise based HTTP client for the browser and node.js.
- Android Android is a mobile operating system developed by Google.
- AppAuth-Android Android client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
- Docker independent container platform that enables organizations to seamlessly build, share and run any application, anywhere—from hybrid cloud to the edge.
Running the application
Follow these steps to set up and run this code pattern. The steps are described in detail below.
Prerequisites
Steps
- Clone the repo
- Setup IBM IAM
- Create IBM Cloud services
- Configure Watson Assistant
- Deploy NodeJS server to Kubernetes
- Configure Android Application
- Run the application
1. Clone the repo
Clone this repository in a folder your choice:
git clone https://github.com/IBM/kubernetes-speech-assistant.git
cd Kubernetes-speech-assistant
2. Setup IBM IAM
- Login into your
IBM Cloud
account. - On the main dashboard, click
Manage
and under that Access (IAM)
. - On the left pane, click
IBM Cloud API keys
. - Click on
Create an IBM Cloud API key
. - GIve your key a name and click
create
. - Copy the key.

- Navigate to the file
app/src/main/java/com/example/kubernetesassistant/AppConfigTemplate.java
and paste the API_KEY
value with the one copied.

- Rename
app/src/main/java/com/example/kubernetesassistant/AppConfigTemplate.java
to app/src/main/java/com/example/kubernetesassistant/AppConfig.java
.
cd app/src/main/java/com/example/kubernetesassistant
mv AppConfigTemplate.java AppConfig.java
3. Create IBM Cloud services
- Create the IBM Cloud Kubernetes Service. You can find the service in the
Catalog
. For this code pattern, we can use the Free
cluster, and give it a name. Note, that the IBM Cloud allows one instance of a free cluster and expires after 30 days.


- Go to your provisioned Watson Assistant service on IBM Cloud. Create new credentials and enter them into the config.

- Click on
Launch Watson Assistant
.

- Create a skill using the existing json in the repository.

- Create an Assistant, and add the skill to the Assistant.

- Get the Assistant ID and enter it into the config file.

- Rename
server/config-template.json
to config.json
.
cd server
mv config-template.json config.json
5. Deploy NodeJS server to Kubernetes
- Navigate to the
server
directory in the cloned repository.
cd server
- Build the
Dockerfile
and push the image to your account on Dockerhub.
docker build -t <DOCKERHUB_USERNAME>/kubernetes-assistant .
docker push <DOCKERHUB_USERNAME>/kubernetes-assistant
Modify the manifest.yml
file (Line 15), to replace <DOCKERHUB_USERNAME>
to your username.
Go to your provisioned Kubernetes
service on IBM Cloud, and run the commands displayed in the access
tab.

- Deploy the
manifest.yml
on to your Kubernetes cluster.
kubectl apply -f manifest.yml
- Run the command
kubectl get svc
, and copy the external IP address.
- Open the codebase in
Android Studio
or an IDE of your choice. - Navigate to the file
app/src/main/java/com/example/kubernetesassistant/AppConfig.java
and paste the SERVER_URL
value with the IP address copied.
7. Run the application
Use Android Studio
or the CammandLine
to generate an APK and install the application on your Android Mobile device.
Run the application.
Links
License
This code pattern is licensed under the Apache Software License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.
Apache Software License (ASL) FAQ