"""
Deploy ML models using Flask by executing the application with the command:
python app.pyThis process involves using an HTML form and a pickle file to run predictions and display outputs.
To containerize your application with Docker, follow these steps:
- Build the Docker image:
docker build -t my-app .- Run the Docker container:
docker run -p 5000:5000 my-appAccess the app at http://localhost:5000/.
Deploy your app on Kubernetes with the following commands:
- Start Minikube:
minikube start- Build the image within Minikube:
minikube image build -t my-app .- Deploy the application:
cd kubernetes
kubectl apply -f deployment.yaml
kubectl apply -f service.yamlCheck the deployment and service:
kubectl get pods
kubectl get svcLaunch the app in a browser:
minikube service my-serviceFor AWS ECS deployment, prepare your Docker image and push it to AWS ECR:
- Build the image (for M1 chip, use --platform=linux/amd64):
docker build -t my-app --platform=linux/amd64 .- Authenticate with AWS ECR:
aws ecr get-login-password --region ca-central-1 | docker login --username AWS --password-stdin <account_id>.dkr.ecr.ca-central-1.amazonaws.com- Tag and push the Docker image:
docker tag my-app:latest <account_id>.dkr.ecr.ca-central-1.amazonaws.com/my-repo:latest- Push the image to AWS ECR:
docker push <account_id>.dkr.ecr.ca-central-1.amazonaws.com/my-repo:latestIn AWS ECS, create a cluster and an instance with a network. Then create a task definition where you define the container specifications and provide the URL for the image. For Flask apps, use port 5000.
Define a service in ECS to access the container and ensure the EC2 instance allows inbound and outbound traffic.
- Delete the Kubernetes deployment:
kubectl delete service my-service
kubectl delete deployment model-deployment- Stop Minikube:
minikube stop