Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy app to AKS with Azure private registry #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
CMD ["python", "app.py"]
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
# Deployment on Microsoft Azure using docker container
# 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 <USER_NAME> and <YOUR_KEY> for the command below
kubectl create secret docker-registry azure-reg-cred \
--docker-username=<USER_NAME> \
--docker-password=<YOUR_KEY> \
--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
```
44 changes: 44 additions & 0 deletions azure_deployment.yaml
Original file line number Diff line number Diff line change
@@ -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