Step 2: Download Canada population andshapefile you can search and Download Canada shapefile from Statistics Canada or pull it from Github(https://github.com/zhuby1973/geopandas.git)
the shapefile include 3 files, we need save it in same folder: lpr_000b16a_e.dbf lpr_000b16a_e.shp lpr_000b16a_e.shx
Step 3: Begin to code
import pandas as pd
import numpy as np
import geopandas as gpd
import matplotlib.pyplot as plt
#load Canada shapefile
fp = "lpr_000b16a_e.shp"
map_df = gpd.read_file(fp)
#load Canada population csv file
province = pd.read_csv("1710000901-eng.csv", sep=",")
# join the geodataframe with the csv dataframe
merged = map_df.merge(province, how='left', left_on="PRENAME", right_on="Geography")
merged=merged.rename(index=str, columns={"PRENAME":"PRENAME", "geometry":"geometry", "Q4 2020":"population"})
# add province name and populations on map
fig = plt.figure(1, figsize=(25,15))
ax = fig.add_subplot()
merged.apply(lambda x: ax.annotate(text=x.PRENAME + "\n" + str(x.population), xy=x.geometry.centroid.coords[0], ha='center', fontsize=14, color='blue'), axis=1);
merged.boundary.plot(ax=ax, color='Black', linewidth=.4)
merged.plot(ax=ax, cmap='Pastel2', figsize=(12, 12))
ax.text(-0.05, 0.5, 'http://pythondesign.ca/', transform=ax.transAxes,
fontsize=20, color='gray', alpha=0.5,
ha='center', va='center', rotation='90')
output from one_thread.py:
ubuntu@ubuntu2020:~$ time curl http://192.168.0.171:5000
{"result_file": "file result", "result_db": "db result", "result_api": "api result"}
real 0m0.629s
user 0m0.009s
sys 0m0.013s
output from multiple_threads.py:
ubuntu@ubuntu2020:~$ time curl http://192.168.0.171:5000
{"result_file": "file result", "result_db": "db result", "result_api": "api result"}
real 0m0.328s
user 0m0.014s
sys 0m0.010s
the real time is dropped from 629ms to 328ms with multiple threads!
from flask import Flask
server = Flask(__name__)
@server.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
server.run(host='0.0.0.0')
pyinstaller -F server.py
it will create a executable file server in ./dist
verify the executable file
root@labvm:~/python_docker/src/dist# ./server
* Serving Flask app "server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
if you have static and templates folder and other py files, you can run command like: pyinstaller -F -i BreezePython.ico --add-data="HttpServer\static;HttpServer\static" --add-data="HttpServer\templates;Httpserver\templates" --add-data="settings.py;." manage.py
another way to create and attach to acr
az login
az group create –name HansResourceGroup –location eastus
az aks create –resource-group HansResourceGroup –name myAKSCluster –node-count 1 –enable-addons monitoring –generate-ssh-keys
az aks get-credentials –resource-group HansResourceGroup –name myAKSCluster
az aks update -n myAKSCluster -g HansResourceGroup –attach-acr registryjrm1796
az acr repository list –name registryjrm1796 –output table
az acr repository show-tags –name registryjrm1796 –repository user-java –output table
az acr list –resource-group teamResources –query "[].{acrLoginServer:loginServer}" –output table
Connect to the cluster
az aks get-credentials –resource-group teamResources –name userAKSCluster
kubectl get nodes
Deploy azure-vote sample app to AKSCluster
root@labvm:~/azure-voting-app-redis/azure-vote# kubectl apply -f https://raw.githubusercontent.com/zhuby1973/azure/main/azure-vote.yaml
deployment.apps/azure-vote-back created
service/azure-vote-back created
deployment.apps/azure-vote-front created
service/azure-vote-front created
Test the application
root@labvm:~/azure-voting-app-redis/azure-vote# kubectl get service azure-vote-front –watch
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
azure-vote-front LoadBalancer 10.0.183.193 20.75.153.18 80:32384/TCP 25s
you can verify it on http://20.75.153.18/
NOTE commands to push docker images to acr, use user-java image as example:
az login
az acr login –name registryjrm1796
docker tag user-java registryjrm1796.azurecr.io/user-java:latest
docker push registryjrm1796.azurecr.io/user-java
then you should be able to find user-java in Container registries/registryjrm1796/Repositories on https://portal.azure.com/