In this section, you will deploy an application that leverages the Watson Speech To Text service.
In this section, you will create the Watson service in your own account and get the service credentials.
- Go to cloud.ibm.com and using the account switcher drop down, switch to your own Account.
- Click on the Catalog, search for Speech To Text service and Create
- Click on Service Credentials on the left
- Click the dropdown arrow on the credentials to expand it.
- Take note of the
apikey
value. You will need this key in the next section
-
Change to the Exercise 4 directory:
cd ../exercise-4
-
Edit the credentials.json file found in
watson/credentials.json
.
nano watson/credentials.json
-
Update the
apikey
value with the value from the previous section and then save the file. -
Create a Kubernetes Secret from on the credentials stored in this file.
kubectl create secret generic apikey --from-file=./watson/credentials.json
-
List secrets to see your secret called
apikey
.
kubectl get secret
-
Create a unique application name for the watson app you're about to build. Something like
bmv-watson-1111
export MYWATSONAPP=<your_unique_name>
-
Build the image, and push it to the IBM Cloud Container Registry using the
ibmcloud cr build
command.ibmcloud cr build -t $MYREGISTRY/$MYNAMESPACE/$MYWATSONAPP ./watson
-
List images to find your new image. You will need the image name in the next step.
ibmcloud cr images
- Edit the watson-deployment.yml file and update the image tag with the registry path to the image you just created.
nano watson-deployment.yml
Here is the relevant part for you to edit:
yml spec: containers: - name: watson-speech-to-text image: "us.icr.io/<namespace>/<appname>" # edit here! # change to the path of the watson image you just built and pushed # ex: image: "us.icr.io/code-camp/bmv-watson-1234"
Take a close look at the watson-deployment.yaml and look for the volumeMounts and volumes section. This is how we tell Kubernetes to share the apikey
secret we created with the container. It writes the contents of the secret into /var/credentials of the container.
volumeMounts:
- mountPath: /var/credentials
name: apikeyvol
...
volumes:
- name: apikeyvol
secret:
secretName: apikey
There is nothing you need to do for this section.
The yaml file has everything we need defined. We simply give this file to kubectl to apply the configuration.
-
Create the deployment, pods and services making up your application using the .yml file.
kubectl apply -f watson-deployment.yml
-
You can open the Kubernetes dashboard and explore all the new objects created or use the following commands.
kubectl get pods,deployments,services
In the previous sections, you exposed applications using service type NodePort
. NodePort is good for development purposes, but when you are ready to go live, you need a permanent IP address or host name. For that, you need to create a service type of either LoadBalancer
or create a Kubernetes Ingress
.
Standard clusters on IKS come with an IBM-provided domain. This gives you a better option to expose applications with a proper URL and on standard HTTP/S ports. In this section, we'll use Ingress to set up the cluster inbound connection to the service.
-
Get the Ingress information for your cluster
ibmcloud ks cluster get --cluster $MYCLUSTER
Example output:
Name: mydemocluster ID: f4f207d35a2b4fe98998d7ba0d State: normal Created: 2018-12-06T16:11:59+0000 Location: dal13 ... Ingress Subdomain: mydemocluster.us-south.containers.appdomain.cloud Ingress Secret: mydemocluster ...
-
Note the
Ingress Subdomain
andIngress Secret
values. You'll need this in the next step. -
In
watson-ingress.yaml
, update the three locations marked<Ingress Subdomain>
and<Ingress Secret>
.
nano watson-ingress.yaml
Here is the relevant portion you need to edit:
spec:
tls:
- hosts:
- watson.<Ingress Subdomain>
secretName: <Ingress Secret>
rules:
- host: watson.<Ingress Subdomain>
```
![](../README_images/watson-ingress.png)
4. Apply this yaml to your cluster.
```
kubectl apply -f watson-ingress.yaml
```
4. In a new browser tab, go to your application! The URL will be `https://watson.<Ingress Subdomain>`
![](../README_images/watson-stt.png)
You should be able to click the **Record** button and start speaking into your microphone. Watch the text get trascribed live!
## Clean up
1. Clean up the deployment, pods, and services you created:
```
kubectl delete -f watson-deployment.yml
```
2. Clean up the Ingress you created:
kubectl delete -f watson-ingress.yaml
3. Clean up the images in the registry.
ibmcloud cr image-rm $MYREGISTRY/$MYNAMESPACE/$MYWATSONAPP
4. If you created a Watson Speech to Text service at the beginning of this exercise, return to the browser tab where it is open. Click `Actions > Delete Service` and then click 'Ok' to delete the service.
Continue on to [Exercise 5](../exercise-5/README.md)