Set Up Your Azure Cognitive Services
- Login to the [Azure Portal](https://portal.azure.com/).
- Navigate to the Azure Cognitive Services and create a new service instance for the specific service you are interested in, such as Computer Vision, Text Analytics, etc.
- Once created, note down the keys and the endpoint URL provided in the 'Keys and Endpoint' section.
Install and Configure the Azure CLI
- Ensure you have the Azure CLI installed on your local machine. If not, [download and install it](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).
- Log in to Azure using the CLI with the following command:
az login
- Configure your default subscription by running:
az account set --subscription "your-subscription-name"
Set Up a Kubernetes Cluster
- You can create a Kubernetes cluster using Azure Kubernetes Service (AKS). First, install the kubectl CLI tool if it's not already installed using:
az aks install-cli
- Now, create a resource group:
az group create --name myResourceGroup --location eastus
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
- Get the kubectl context for the created cluster:
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
Deploy Your Application to Kubernetes
- Create a Kubernetes secret to store your Azure Cognitive Services keys for secure access:
kubectl create secret generic azure-cognitive-secret --from-literal=apiKey=YOUR_API_KEY --from-literal=endpoint=YOUR_ENDPOINT_URL
- Write a Kubernetes deployment YAML manifest file to deploy your application. Reference the secret in your application as environment variables:
apiVersion: apps/v1
kind: Deployment
metadata:
name: cognitive-service-app
spec:
replicas: 1
selector:
matchLabels:
app: cognitive-service-app
template:
metadata:
labels:
app: cognitive-service-app
spec:
containers:
- name: cognitive-service-container
image: your-docker-image
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: azure-cognitive-secret
key: apiKey
- name: ENDPOINT
valueFrom:
secretKeyRef:
name: azure-cognitive-secret
key: endpoint
- Apply the deployment configuration:
kubectl apply -f deployment.yaml
- Verify that the pod is running with:
kubectl get pods
Expose Your Service
- Create a service to expose your deployment. You can choose to expose it as a LoadBalancer, NodePort, or ClusterIP. Here’s an example of a LoadBalancer service manifest:
apiVersion: v1
kind: Service
metadata:
name: cognitive-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: cognitive-service-app
- Apply the service configuration:
kubectl apply -f service.yaml
- Check the external IP of the service using:
kubectl get svc cognitive-service
Test Your Application
- Access the service using the external IP obtained in the previous step and verify the integration of Azure Cognitive Services with your application running on Kubernetes.
- Ensure your application is able to interact with the Azure Cognitive Services endpoints securely using the stored API keys.