|
| 1 | +--- |
| 2 | +title: Deploy and run an Azure OpenAI ChatGPT application on AKS via Terraform |
| 3 | +description: This article shows how to deploy an AKS cluster and Azure OpenAI Service via Terraform and how to deploy a ChatGPT-like application in Python. |
| 4 | +ms.topic: quickstart |
| 5 | +ms.date: 09/06/2024 |
| 6 | +author: aamini7 |
| 7 | +ms.author: ariaamini |
| 8 | +ms.custom: innovation-engine, linux-related-content |
| 9 | +--- |
| 10 | + |
| 11 | +## Provision Resources with Terraform (~5 minutes) |
| 12 | +Run terraform to provision all the Azure resources required to setup your new OpenAI website. |
| 13 | +```bash |
| 14 | +# Terraform parses TF_VAR_* as vars (Ex: TF_VAR_name -> name) |
| 15 | +export TF_VAR_location="westus3" |
| 16 | +export TF_VAR_kubernetes_version="1.30.9" |
| 17 | +export TF_VAR_model_name="gpt-4o-mini" |
| 18 | +export TF_VAR_model_version="2024-07-18" |
| 19 | +# Terraform consumes sub id as $ARM_SUBSCRIPTION_ID |
| 20 | +export ARM_SUBSCRIPTION_ID=$SUBSCRIPTION_ID |
| 21 | +# Run Terraform |
| 22 | +terraform -chdir=terraform init |
| 23 | +terraform -chdir=terraform apply -auto-approve |
| 24 | +``` |
| 25 | + |
| 26 | +## Login to Cluster |
| 27 | +In order to use the kubectl to run commands on the newly created cluster, you must first login. |
| 28 | +```bash |
| 29 | +RESOURCE_GROUP=$(terraform -chdir=terraform output -raw resource_group_name) |
| 30 | +az aks get-credentials --admin --name AksCluster --resource-group $RESOURCE_GROUP --subscription $SUBSCRIPTION_ID |
| 31 | +``` |
| 32 | + |
| 33 | +# Install Helm Charts |
| 34 | +Install nginx and cert-manager through Helm |
| 35 | +```bash |
| 36 | +helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx |
| 37 | +helm repo add jetstack https://charts.jetstack.io |
| 38 | +helm repo update |
| 39 | + |
| 40 | +STATIC_IP=$(terraform -chdir=terraform output -raw static_ip) |
| 41 | +DNS_LABEL=$(terraform -chdir=terraform output -raw dns_label) |
| 42 | +helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \ |
| 43 | + --set controller.replicaCount=2 \ |
| 44 | + --set controller.nodeSelector."kubernetes\.io/os"=linux \ |
| 45 | + --set defaultBackend.nodeSelector."kubernetes\.io/os"=linux \ |
| 46 | + --set controller.service.annotations."service\.beta\.kubernetes\.io/azure-dns-label-name"=$DNS_LABEL \ |
| 47 | + --set controller.service.loadBalancerIP=$STATIC_IP \ |
| 48 | + --set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz |
| 49 | +helm upgrade --install cert-manager jetstack/cert-manager \ |
| 50 | + --set crds.enabled=true \ |
| 51 | + --set nodeSelector."kubernetes\.io/os"=linux |
| 52 | +``` |
| 53 | + |
| 54 | +## Deploy |
| 55 | +Apply/Deploy Manifest File |
| 56 | +```bash |
| 57 | +export IMAGE="aamini8/magic8ball:latest" |
| 58 | +# Uncomment below to manually build docker image yourself instead of using pre-built image. |
| 59 | +# docker build -t <YOUR IMAGE NAME> ./magic8ball --push |
| 60 | +export HOSTNAME=$(terraform -chdir=terraform output -raw hostname) |
| 61 | +export WORKLOAD_IDENTITY_CLIENT_ID=$(terraform -chdir=terraform output -raw workload_identity_client_id) |
| 62 | +export AZURE_OPENAI_DEPLOYMENT=$(terraform -chdir=terraform output -raw openai_deployment) |
| 63 | +export AZURE_OPENAI_ENDPOINT=$(terraform -chdir=terraform output -raw openai_endpoint) |
| 64 | +envsubst < quickstart-app.yml | kubectl apply -f - |
| 65 | +``` |
| 66 | + |
| 67 | +## Wait for host to be ready |
| 68 | +```bash |
| 69 | +kubectl wait --for=condition=Ready certificate/tls-secret |
| 70 | +echo "Visit: https://$HOSTNAME" |
| 71 | +``` |
0 commit comments