Skip to content

Example project to automate the setup of `Watson NLP for embed` on an IBM Cloud Kubernetes cluster.

License

Notifications You must be signed in to change notification settings

thomassuedbroecker/terraform-vpc-kubernetes-watson-nlp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Run Watson NLP for Embed on an IBM Cloud Kubernetes cluster

This example project has two objectives.

The example project reuses code from project Use Terraform to create a VPC and a Kubernetes Cluster on IBM Cloud.

Visit the related blog post Run Watson NLP for Embed on an IBM Cloud Kubernetes cluster in a Virtual Private Cloud environment.

Simplified IBM Cloud architecture diagram

Terraform will create and configure on IBM Cloud:

  • 1 x VPC

    • 3 x Security Groups

      • 1 x Default
      • 2 x Related to the Kubernetes Cluster (created by the Kubernetes Service creation)
    • 1 x Access control list

    • 1 x Routing table

    • 1 x Public gateway

    • 1 x Virtual Private Endpoint Gateway (created by the Kubernetes Service creation)

    • 1 x Public load balancer (created by the Kubernetes Service creation)

  • 1 x Kubernetes Cluster

This is a simplified diagram of the created infrastructure with terraform.

Prerequisites

To use the bash automation you need to have following tools to be installed on your local computer:

Example setup

The example setup contains two bash automations:

Step 1: Clone the repo

git clone https://github.com/thomassuedbroecker/terraform-vpc-kubernetes-watson-nlp.git
cd terraform-vpc-kubernetes-watson-nlp

Create the Kubernetes cluster and VPC

Step 1: Navigate to the terraform_setup

cd code/terraform_setup

Step 2: Create a .env file

cat .env_template > .env

Step 3: Add an IBM Cloud access key to your local .env file

nano .env

Content of the file:

export IC_API_KEY=YOUR_IBM_CLOUD_ACCESS_KEY
export REGION="us-east"
export GROUP="tsuedbro"

Step 4: Verify the global variables in the bash script automation

Inspect the bash automation create_vpc_kubernetes_cluster_with_terraform.sh and adjust the values to your need.

nano create_vpc_kubernetes_cluster_with_terraform.sh
#export TF_LOG=debug
export TF_VAR_flavor="bx2.4x16"
export TF_VAR_worker_count="2"
export TF_VAR_kubernetes_pricing="tiered-pricing"
export TF_VAR_resource_group=$GROUP
export TF_VAR_vpc_name="watson-nlp-tsuedbro"
export TF_VAR_region=$REGION
export TF_VAR_kube_version="1.25.5"
export TF_VAR_cluster_name="watson-nlp-tsuedbro"

Step 5: Execute the bash automation

The creation can take up to 1 hour, depending on the region you use.

sh create_vpc_kubernetes_cluster_with_terraform.sh
  • Example output:
...
Apply complete! Resources: 5 added, 0 changed, 0 destroyed.
*********************************

Deploy Watson NLP embed with Helm

Step 1: Navigate to the helm_setup

cd code/helm_setup

Step 2: Create a .env file

cat .env_template > .env

Step 3: Add an IBM Cloud access key to your local .env file

export IC_API_KEY=YOUR_IBM_CLOUD_ACCESS_KEY
export IBM_ENTITLEMENT_KEY="YOUR_KEY"
export IBM_ENTITLEMENT_EMAIL="YOUR_EMAIL"
export CLUSTER_ID="YOUR_CLUSTER"
export REGION="us-east"
export GROUP="tsuedbro"

Step 4: Execute the bash automation

sh deploy-watson-nlp-to-kubernetes.sh

The script does following steps and the links are pointing to the relevant function in the bash automation:

  1. Log on to IBM Cloud with an IBM Cloud API key.
  2. It ensures that is connected to the cluster.
  3. It creates a Docker Config File which will be used to create a pull secret.
  4. It installs the Helm chart for Watson NLP embed configured for REST API usage.
  5. It verifies that the container is running and invokes a REST API call inside the runtime-container of Watson NLP emded.
  6. It verifies that the exposed Kubernetes URL with a load balancer service is working and invokes a the same REST API call as before from the local machine.
  • Example output:
*********************
loginIBMCloud
*********************

...

*********************
connectToCluster
*********************

OK
...

*********************
createDockerCustomConfigFile
*********************

IBM_ENTITLEMENT_SECRET: 
...

*********************
installHelmChart
*********************

...

*********************
verifyDeploment
*********************


------------------------------------------------------------------------
Check watson-nlp-container
Status: watson-nlp-container
2023-01-12 09:43:32 Status: watson-nlp-container is created
------------------------------------------------------------------------

*********************
verifyPod could take 10 min
*********************


------------------------------------------------------------------------
Check watson-nlp-container
Status: 0/1
2023-01-12 09:43:32 Status: watson-nlp-container(0/1)
------------------------------------------------------------------------
Status: 0/1
2023-01-12 09:44:33 Status: watson-nlp-container(0/1)
------------------------------------------------------------------------
Status: 1/1
2023-01-12 09:45:34 Status: watson-nlp-container is created
------------------------------------------------------------------------

*********************
verifyWatsonNLPContainer
*********************

Pod: watson-nlp-container-557d9fcf68-wm4vp

Result of the Watson NLP API request:
http://localhost:8080/v1/watson.runtime.nlp.v1/NlpService/SyntaxPredict

{"text":"This is a test sentence.", "producerId":{"name":"Izumo Text Processing", "version":"0.0.1"}, "tokens":[{"span":{"begin":0, "end":4, "text":"This"}, "lemma":"", "partOfSpeech":"POS_UNSET", "dependency":null, "features":[]}, {"span":{"begin":5, "end":7, "text":"is"}, "lemma":"", "partOfSpeech":"POS_UNSET", "dependency":null, "features":[]}, {"span":{"begin":8, "end":9, 
...

The image below shows the running container on the Kubernetes cluster.

About

Example project to automate the setup of `Watson NLP for embed` on an IBM Cloud Kubernetes cluster.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published