Step 1: Installations
Windows Subsystem for Linux Installation Guide for Windows 10 (Link). Follow the manual Installation steps (Link)
Download Docker for desktop (Link). Make sure that docker is running “Windows Docker Engine” (as we are working in VM). To do so right click on the docker icon in “hidden icons” in taskbar and click on “Switch to Windows Container…”
Step 2: Create Docker File in Visual Studio Code
Install Visual Studio Code. Install Docker plugin; Install Azure tools plugin; Install python plugin. Open your folder where you have created your project folder in Visual Studio Code and perform the following tasks:
- Install Azure-CLI for the system (Link). Once Installed, check by running following command for Login into azure account.
az login
- (OPTIONAL) If you have multiple subscriptions, then set the Subscription on which you are working by using following command (link)
az account set --subscription "<subscription-id>"
- To verify you can work with the Container registry and push a docker image; login to the Azure Container Registry (ACR) using following command
az acr login -n <Azure-Container-Registry-Name>
- Create your Docker file for the project. Use the following code as templet to build your own docker file. Save your docker file in same project folder with no extension and name should be “Dockerfile”
FROM ubuntu
LABEL maintainer="Organization Name"
LABEL developer="Shreyans Jain"
RUN apt update
RUN apt --assume-yes install python3 python3-pip
RUN python3 -m pip install --no-cache dir pandas==1.0.3 numpy==1.19.4
RUN python3 -m pip install --no-cache-dir scikit-learn==0.22.2.post1 xlrd==1.2.0 xgboost==1.0.2
RUN python3 -m pip install --no-cache-dir flask==1.1.1 flask-cors==3.0.8 flask-restful==0.3.8
RUN mkdir -p /<new_folder>
COPY <my_project_folder> /<new_folder> # <my_project_folder> is my project folder
WORKDIR /<new_folder>
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]
- Now we will build the docker file directly into ACR. To build your docker file run the following command: (Link)
az acr build --registry <ACR_Name> --image <New_Image_Name>
- Wait until the build is successful. To verify the build and to check whether your new docker image is created in your ACR, run the following command:
az acr repository list --name <ACR_Name> --output table
Step 3: Connect ACR with AKS
To attach ACR with AKS use the following command: (Link)
az aks update -n <AKS_Name> -g <Resource_Group_Name> --attach-acr <acr_name>
Step 4: Create YAML for deployment
Create a YAML File (refer previous yml files). Save the file on same level as Dockerfile, with extension as “.yml”
apiVersion: v1
kind: Service
metadata:
name: hello-python-service
spec:
selector:
app: hello-python
ports:
- protocol: "TCP"
port: 6000
targetPort: 5000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-python
spec:
selector:
matchLabels:
app: hello-python
replicas: 4
template:
metadata:
labels:
app: hello-python
spec:
containers:
- name: hello-python
image: hello-python:latest
imagePullPolicy: Never
ports:
- containerPort: 5000
Note: To learn how to write a YAML file, you can refer this link.
Step 5: Deploy your container to the AKS
- Ensure you are working on correct AKS
az aks get-credentials -g <Resource_Group_Name> -n <AKS_Name>
- Push your “.yml” file on AKS using following command:
kubectl apply -f <.yml file>
- Check your deployment by running following command:
kubectl get pods --watch
- To Manage AKS Clusters use this Link. Use this link for steps to start and stop the AKS Cluster. It is used when a update is made to clusters.
- (OPTIONAL) To add a new nodepool to your AKS, follow the following templet: (link)
az aks nodepool add \
--resource-group <Resource_Group_Name> \
--cluster-name <AKS_Name> \
--name <nodepool_name>\
--mode System \
--node-count 1 \
--node-vm-size Standard_NCasT4_v3 \
--max-pods 30 \
--node-taints sku=gpu:NoSchedule \
--no-wait
Note:
–node-vm-size mentioned here is a GPU based VM. The list of VM’s available for AKS is ever expanding. To check which VM is available in your subscription location, you can run command available here
Other Important Links:
Frequently asked questions about Azure Kubernetes Service (AKS) – https://docs.microsoft.com/en-us/azure/aks/faq
Tutorial: Prepare an application for Azure Kubernetes Service (AKS) – https://docs.microsoft.com/en-us/azure/aks/tutorial-kubernetes-prepare-app
GPU Node Pool – https://docs.microsoft.com/en-us/azure/aks/use-multiple-node-pools#specify-a-taint-label-or-tag-for-a-node-pool