diff --git a/Dockerfile b/Dockerfile index 3fc01e1..d1993c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,8 +11,13 @@ ADD . /app # Install dependencies RUN pip install -r requirements.txt +# Resolve issue "ImportError: cannot import name 'soft_unicode' from 'markupsafe'" +# https://github.com/aws/aws-sam-cli/issues/3661#issuecomment-1049916359 +RUN pip uninstall -y markupsafe +RUN pip install markupsafe==2.0.1 + # Expose port EXPOSE 5000 # Run the application: -CMD ["python", "app.py"] \ No newline at end of file +CMD ["python", "app.py"] diff --git a/README.md b/README.md index ff8d932..62258a6 100644 --- a/README.md +++ b/README.md @@ -1 +1,70 @@ -# Deployment on Microsoft Azure using docker container \ No newline at end of file +# Deployment on Microsoft Azure Kubernetes Service (AKS) using docker container + +The following commands can be used in Azure Cloud Shell via the browser. First you need to login to [Azure Portal](https://portal.azure.com/) then click on Cloud Shell using Bash. +You can see steps by steps instruction [here](https://medium.com/@phylypo/deploy-a-pycaret-app-to-aks-using-azure-container-registry-fc9e56c378d0). + +``` +# setup variables to use +RESOURCE_GROUP=PYCARET-KUBE-RG +CLUSTER_NAME=PYCARET-AKS +ACR_NAME=pycaretacr + +# create resource group, make sure the resource gropu name is new so we can cleanup at the end +az group create --name $RESOURCE_GROUP --location westus2 + +# create Aure Container Registry (ACR) +az acr create --resource-group $RESOURCE_GROUP --name $ACR_NAME --sku Premium + +# clone the git repo and go into repo directory +# git clone https://... +cd pycaret-deployment-azure + +# build and put the docker image to Azure registry +az acr build --registry $ACR_NAME --image pycaret-ins-5000:v1 . + +# create kubernetes cluster +az aks create \ + --resource-group $RESOURCE_GROUP \ + --name $CLUSTER_NAME \ + --node-count 2 \ + --enable-addons http_application_routing \ + --enable-managed-identity \ + --generate-ssh-keys \ + --node-vm-size Standard_B2s + +# add node pool +az aks nodepool add \ + --resource-group $RESOURCE_GROUP \ + --cluster-name $CLUSTER_NAME \ + --name mypool \ + --node-count 2 \ + --node-vm-size Standard_B2s + + +# Setup credential to the AKS cluster +az aks get-credentials --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP + +# Enable the access key using Azure portal on ACR +# Copy the username and primary key for below command + +# Create Kubernetes secret with username and password for access to private registry +# updat the and for the command below +kubectl create secret docker-registry azure-reg-cred \ + --docker-username= \ + --docker-password= \ + --docker-server=pycaretacr.azurecr.io + +# create deployment and service on AKS +kubectl apply -f azure_deployment.yaml + +# check pod status for running status +kubectl get pod +# check for service ip +kubectl get service + +# Your should be able to browse to the EXTERNAL-IP from above output and you should see the web interface + +# Cleanup -- when done, use the command below to delete the resource group +# this will also delete all the resources in this resource group so you don't incure any futher cost +az group delete --name $RESOURCE_GROUP --yes --no-wait +``` diff --git a/azure_deployment.yaml b/azure_deployment.yaml new file mode 100644 index 0000000..f526d84 --- /dev/null +++ b/azure_deployment.yaml @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: azure-insurance +spec: + replicas: 1 + selector: + matchLabels: + app: azure-insurance + template: + metadata: + labels: + app: azure-insurance + spec: + nodeSelector: + "kubernetes.io/os": linux + containers: + - name: azure-insurance + image: pycaretacr.azurecr.io/pycaret-ins-5000:v1 + imagePullPolicy: Always + resources: + requests: + cpu: 100m + memory: 512Mi + limits: + cpu: 1250m + memory: 512Mi + ports: + - containerPort: 80 + imagePullSecrets: + - name: azure-reg-cred + +--- +apiVersion: v1 +kind: Service +metadata: + name: azure-insurance +spec: + type: LoadBalancer + ports: + - port: 80 + targetPort: 5000 + selector: + app: azure-insurance