Prerequisites
- Ensure you have a Kubernetes cluster running. You might use local solutions like Minikube or cloud providers like GKE, EKS, or AKS.
- Install the IBM Cloud CLI and the IBM Cloud Kubernetes Service plug-in.
- Set up an IBM Watson service instance with the appropriate credentials.
- Ensure `kubectl` is installed and configured to interact with your Kubernetes cluster.
Setup IBM Cloud CLI
- Log in to IBM Cloud using the CLI:
ibmcloud login
- Install the Kubernetes Service plug-in:
ibmcloud plugin install kubernetes-service
- Access your Kubernetes cluster:
ibmcloud ks cluster config --cluster <cluster-name-or-id>
Create a Watson Service on IBM Cloud
- Navigate to IBM Cloud catalog and select the Watson service you need (e.g., Watson Assistant).
- Follow the instructions to create the service instance and note the credentials provided.
Creating a Kubernetes Secret for Watson Credentials
- Create a secret in Kubernetes to securely store your Watson service credentials:
kubectl create secret generic watson-credentials --from-literal=username=<your-username> --from-literal=password=<your-password>
Deploying Watson API on Kubernetes
- Create a deployment YAML file to define the Watson API setup. Include environment variables to consume the Kubernetes secret:
apiVersion: apps/v1
kind: Deployment
metadata:
name: watson-deployment
spec:
replicas: 1
selector:
matchLabels:
app: watson
template:
metadata:
labels:
app: watson
spec:
containers:
- name: watson-container
image: <your-watson-image>
env:
- name: WATSON_USERNAME
valueFrom:
secretKeyRef:
name: watson-credentials
key: username
- name: WATSON_PASSWORD
valueFrom:
secretKeyRef:
name: watson-credentials
key: password
- Apply the YAML to deploy it:
kubectl apply -f watson-deployment.yaml
Expose the Watson API
- Create a service definition file to expose the Watson API deployment:
apiVersion: v1
kind: Service
metadata:
name: watson-service
spec:
selector:
app: watson
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
- Apply the service configuration:
kubectl apply -f watson-service.yaml
Verify the Integration
- Get the external IP of the service by running:
kubectl get svc watson-service
- Use this external IP to send requests to your Watson API and verify if it's working as expected.
- Ensure your application is configured to route requests to this service.