<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alvaro Valarezo de la Fuente</title>
    <description>The latest articles on DEV Community by Alvaro Valarezo de la Fuente (@alvaroraul7).</description>
    <link>https://dev.to/alvaroraul7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F928606%2F8aeca03c-4c4a-41e6-aeb5-0d6493ba6b3e.png</url>
      <title>DEV Community: Alvaro Valarezo de la Fuente</title>
      <link>https://dev.to/alvaroraul7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alvaroraul7"/>
    <language>en</language>
    <item>
      <title>Deploy a ML model using Google Cloud Run, Github Actions and Terraform</title>
      <dc:creator>Alvaro Valarezo de la Fuente</dc:creator>
      <pubDate>Tue, 25 Oct 2022 14:17:12 +0000</pubDate>
      <link>https://dev.to/alvaroraul7/create-and-deploy-a-ml-model-using-google-cloud-run-github-actions-and-terraform-3d6b</link>
      <guid>https://dev.to/alvaroraul7/create-and-deploy-a-ml-model-using-google-cloud-run-github-actions-and-terraform-3d6b</guid>
      <description>&lt;p&gt;&lt;em&gt;In this post. I will explain how to expose an API in Python using FastAPI from a trained model, use best CI/CD practices (Github Actions) and IaC (Terraform) to automate infrastructure creation.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerrequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Docker Desktop &lt;/li&gt;
&lt;li&gt;Git &lt;/li&gt;
&lt;li&gt;Github Account&lt;/li&gt;
&lt;li&gt;Google Cloud Platform with owner permissions &lt;/li&gt;
&lt;li&gt;Clone this &lt;a href="https://github.com/AlvaroRaul7/fastapi-MlOps"&gt;repo&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Google Cloud Run
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://cloud.google.com/run"&gt;Cloud Run&lt;/a&gt; is a serverless platform from &lt;a href="https://cloud.google.com/"&gt;Google Cloud&lt;/a&gt; to deploy and run containers. Cloud Run can be used to serve Restful web APIs, WebSocket applications, or microservices connected by gRPC. &lt;/p&gt;

&lt;p&gt;In this project we will need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An IAM account with permissions to create a service account&lt;/li&gt;
&lt;li&gt;Cloud Storage Admin permissions&lt;/li&gt;
&lt;li&gt;Cloud Registry Admin permissions&lt;/li&gt;
&lt;li&gt;Google Cloud Run Admin permissions&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  In case you don't want to expose the API for public access:
&lt;/h3&gt;

&lt;p&gt;In the terraform/main.tf:&lt;/p&gt;

&lt;p&gt;Remove the resource &lt;code&gt;"google_cloud_run_service_iam_member"  "run_all_users"&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i3d-dtLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/39871126/195152688-dae361cd-a87f-4757-beb9-2899c3a32db9.png" class="article-body-image-wrapper"&gt;&lt;img alt="image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3d-dtLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/39871126/195152688-dae361cd-a87f-4757-beb9-2899c3a32db9.png" width="880" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ideally, you can set the IAM accounts that can access this api using Google Cloud Run UI or using Terraform. This approach doesn't add any latency to the customer because it uses built-in IAM roles and permissions from Google Cloud.&lt;/p&gt;

&lt;h2&gt;
  
  
  Terraform
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.terraform.io/"&gt;Terraform&lt;/a&gt; is a popular open-source tool for running infrastructure as code. It uses HCL which is a declarative language to declare infrastructure.&lt;br&gt;
The basic flow is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Terraform init&lt;/strong&gt;: Initializes the plugins, backend and many config files Terraform uses to keep tracking of the infrastructure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terraform plan&lt;/strong&gt;: Generates an execution plan for all the infrastructure which is in terraform/main.tf&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terraform apply&lt;/strong&gt;: Apply all the changes that were on the plan.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All steps are declared in the .github/workflows/workflow.yaml&lt;/p&gt;
&lt;h2&gt;
  
  
  Machine Learning Model
&lt;/h2&gt;

&lt;p&gt;It's a logistic regression model that is serialized as a pickle file. It takes as an input a list with 37 parameters and returns a number between 0-1 which determines the probability of a delayed flight.&lt;/p&gt;

&lt;p&gt;Eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  {
"test_array": [
0,0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,1,1,0,1,0,1,0]

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Returns: 0 &lt;br&gt;
In this case it means the flight isn't going to be delayed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it locally
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Fork the &lt;a href="https://github.com/AlvaroRaul7/fastapi-MlOps/"&gt;repo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Clone it in your computer&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;docker build -t ml-api .&lt;/code&gt; in the root of the project to build the image of the api.&lt;/li&gt;
&lt;li&gt;Run  &lt;code&gt;docker run -d --name ml -p 80:8080 ml-api&lt;/code&gt; to create the container using ml-api image built.&lt;/li&gt;
&lt;li&gt;Open &lt;a href="http://localhost/docs"&gt;localhost&lt;/a&gt; to test the project.&lt;/li&gt;
&lt;li&gt;On /predict/ post endpoint, you can use this body as an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  {
"test_array": [
0,0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,1,1,0,1,0,1,0]

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;You should expect a response 200 with a &lt;code&gt;"prediction": 0&lt;/code&gt; which means the flight wasn't delayed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to deploy it with your GCP account
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Generate a Service Account key and upload it in Github Secrets as &lt;code&gt;GCLOUD_SERVICE_KEY&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Push any change in the main branch&lt;/li&gt;
&lt;li&gt;That's it! :)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A bit of stress testing for the API
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;On Mac &lt;code&gt;brew install wrk&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;wrk -t12 -c200 -d45s -s request.lua https://mlops-api-backend-1-5gdi5qltoq-uc.a.run.app/predict/&lt;/code&gt; to open 12 threads with 200 open http connections during 45 seconds.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How can we improve the results
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aXde3Ivo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/39871126/195390648-94d3663d-7b7f-4abf-8e17-325e8ef9e0c3.png" class="article-body-image-wrapper"&gt;&lt;img alt="image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--aXde3Ivo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/39871126/195390648-94d3663d-7b7f-4abf-8e17-325e8ef9e0c3.png" width="880" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best approach would be using horizontal scaling. in this case we can create a 2nd Google Cloud Run instance and use load balancing to distribute the traffic between both instances.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>python</category>
      <category>programming</category>
      <category>devops</category>
    </item>
    <item>
      <title>Develop an API with FastApi, Kubernetes, Traefik and Ansible</title>
      <dc:creator>Alvaro Valarezo de la Fuente</dc:creator>
      <pubDate>Mon, 19 Sep 2022 07:00:12 +0000</pubDate>
      <link>https://dev.to/alvaroraul7/create-an-api-with-fastapi-kubernetes-traefik-and-ansible-16bm</link>
      <guid>https://dev.to/alvaroraul7/create-an-api-with-fastapi-kubernetes-traefik-and-ansible-16bm</guid>
      <description>&lt;h1&gt;
  
  
  kubernetes-fastapi-traefik
&lt;/h1&gt;

&lt;p&gt;Backend API (Python) in FastApi in a Kubernetes Cluster using Traefik as an API Gateway and Ansible as a configuration management tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone Github repo
&lt;/h2&gt;

&lt;p&gt;Clone &lt;a href="https://github.com/AlvaroRaul7/kubernetes-fastapi-traefik"&gt;my repo&lt;/a&gt; and follow the steps below&lt;/p&gt;

&lt;h2&gt;
  
  
  Description of the directories
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ansible : Folder with the resources to deploy the traefik pods using Ansible&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;kubernetes: Folder with the YAML files to deploy the API and the Postgres Database&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;sa-service-2: Folder with the source code of the API&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Requirements for installing the project
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install Docker: &lt;a href="https://docs.docker.com/desktop/mac/install/"&gt;https://docs.docker.com/desktop/mac/install/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: In Docker Desktop Preferences, enable Kubernetes to run the cluster&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ansible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install ansible use pip: &lt;code&gt;python -m pip install --user ansible&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minikube (kubectl)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow these steps: &lt;a href="https://minikube.sigs.k8s.io/docs/start/"&gt;https://minikube.sigs.k8s.io/docs/start/&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Python (PIP)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;openshift&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;pyyaml&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;kubernetes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install python libraries run Eg: &lt;code&gt;pip install openshift&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Helm V3 (Kubernetes Package Manager)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install run &lt;code&gt;brew install helm&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1.- Steps to start the K8s cluster
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;After installing everything above and running Docker Desktop in your PC&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run in your terminal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;minikube start&lt;/code&gt; (Used to initiate a default local cluster with the default namespace)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;minikube tunnel&lt;/code&gt; (Used to get an external ip of the cluster to access in the host OS) (Run it in a separate terminal, Don’t close it)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;kubectl proxy&lt;/code&gt; (Used to forwading the port 8001 to access the k8s dashboard)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to: &lt;a href="http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/deployment?namespace=default"&gt;http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/deployment?namespace=default&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this URL, you can check that there aren’t any deployments yet in the default namespace.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.- Steps to deploy Traefik using Ansible
&lt;/h2&gt;

&lt;p&gt;The Traefik Service is managed by using Ansible, so you can open the file &lt;code&gt;ansible/templates/traefik_values_default.yml.j2&lt;/code&gt; where you can check that the type of deployment is a &lt;strong&gt;DaemonSet&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Traefik listens on port 80 on all interfaces of the host for incoming HTTP requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traefik listens on port 443 on all interfaces of the host for incoming HTTPS request&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traefik dashboard is enabled and is not exposed to the public internet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ports exposed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# To access the dashboard you can use "kubectl port-forward" e.g.:

# kubectl -n traefik port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name -A | head -1) 9000:9000

# Opening http://localhost:9000/dashboard/ should show the dashboard.

traefik:

port: 9000

expose: true

protocol: TCP

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Resources:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# CPU and RAM resource limits. These settings should also be set to

# reasonable values in case of a memory leak e.g.

resources:

requests:

cpu: "100m"

memory: "50Mi"

limits:

cpu: "300m"

memory: "150Mi"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;ansible/defaults/main.yml&lt;/code&gt;, you can change the namespace for the deployment (Traefik) , name for the ingress controller,etc.&lt;/p&gt;

&lt;p&gt;The ansible playbook will detect these settings and apply them to the cluster when it runs the playbook.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;ansible/k8s.yml&lt;/code&gt; you can look that the host is traefik. to recognize this dns we need to edit the &lt;code&gt;/etc/ansible/hosts&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;** If you don’t have the file or folder, please create it using &lt;code&gt;sudo mkdir /etc/ansible&lt;/code&gt; and &lt;code&gt;sudo touch hosts&lt;/code&gt; then edit it:&lt;/p&gt;

&lt;p&gt;and paste this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
[traefik]

localhost

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are telling Ansible that the traefik dns will translate to localhost&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;After doing this we are ready to deploy&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;To deploy the Traefik Service in the traefik namespace:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd ansible&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ansible-playbook --tags=role-traefik-kubernetes --extra-vars action=install k8s.yml&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the final tasks is called &lt;code&gt;TASK [githubixx.traefik-kubernetes : Output rendered template]&lt;/code&gt;. This allows to check the YAML file before Traefik gets deployed&lt;/p&gt;

&lt;p&gt;If everything is OK , run &lt;code&gt;kubectl -n traefik get pods -o wide&lt;/code&gt; and you will see a pod with the traefik initials.&lt;/p&gt;

&lt;p&gt;To forward the ports to check the traefik dashboard, run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kubectl -n traefik port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name -A | head -1) 9000:9000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://localhost:9000/dashboard/#/http/services"&gt;http://localhost:9000/dashboard/#/http/services&lt;/a&gt; to check that everything is working correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps to deploy the Postgres Database
&lt;/h2&gt;

&lt;p&gt;To deploy the database in the K8s cluster, we are going to use diferent YAML files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;code&gt;cd kubernetes&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this folder, there are 4 YAML files for the Postgres Deployment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;postgres-configmap.yaml&lt;/code&gt; A K8s ConfigMap allows me to save important variables like the name of the db, POSTGRES_USER, POSTGRES_PASSWORD.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;postgres-storage.yaml&lt;/code&gt; 2 different kinds of volume: PersistentVolume and PersistentVolumeClaim used to preserve the data if a pod is deleted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;postgres-service.yaml&lt;/code&gt; A K8s Service that allows me to connect to the Postgres DB and with other pods in the same cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;postgres-deployment.yaml&lt;/code&gt; A K8s Deployment with a Postgres 10.1 image.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the kubernetes folder:&lt;/p&gt;

&lt;p&gt;Run:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;kubectl apply -f postgres-configmap.yaml&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;kubectl apply -f postgres-storage.yaml&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;kubectl apply -f postgres-deployment.yaml&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;kubectl apply -f postgres-service.yaml&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you run &lt;code&gt;kubectl get all&lt;/code&gt; you can check that everything is deployed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;kubectl port-forward --namespace default svc/postgres-ip-service 5432:5432&lt;/code&gt; to port forwarding and access the database using &lt;code&gt;localhost:5432&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connect to the database using your favorite DB client like Datagrip, DBeaver,etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inside the users database, run this query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
CREATE TABLE rappiuser (

user_id serial PRIMARY KEY,

name VARCHAR ( 50 ) UNIQUE NOT NULL,

lastname VARCHAR ( 50 ) NOT NULL,

address VARCHAR ( 250 ) NOT NULL,

phone INTEGER NOT NULL,

age INTEGER NOT NULL,

hire_date DATE,

fire_date DATE




);



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s all for the db configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps to deploy the FastApi Backend
&lt;/h2&gt;

&lt;p&gt;Finally, the last step is deploying the API.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;code&gt;cd sa-service-2&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Inside the app folder you can check that is structured in models, schemas, services and utils with a main.py file that contains the routes.&lt;/p&gt;

&lt;p&gt;Inside the sa-service-2 folder, run:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;code&gt;minikube image build -t sa-service-2 .&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This command upload the backend image to the minikube local registry, to use it for the deployment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cd ..&lt;/code&gt; return to the previous dir.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;kubectl apply -f resource-manifests/service-two.yml&lt;/code&gt; Apply a Deployment, Service and an Ingress Controller.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Deployment:&lt;/p&gt;

&lt;p&gt;Define the name for the deployment, and the image that will be used &lt;code&gt;sa-service-2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Service:&lt;/p&gt;

&lt;p&gt;Define the port that will be exposed in this case is the Port 80&lt;/p&gt;

&lt;p&gt;Ingress:&lt;/p&gt;

&lt;p&gt;The Ingress Controller will be handled by Traefik and will listen in the port 80&lt;/p&gt;

&lt;p&gt;Now you can go to &lt;a href="http://localhost/docs"&gt;http://localhost/docs&lt;/a&gt; and start testing the API :)&lt;/p&gt;

&lt;p&gt;In the &lt;a href="http://localhost:9000/dashboard/#/http/services"&gt;http://localhost:9000/dashboard/#/http/services&lt;/a&gt; you can check there is a new ingress controller that handles 2 pods&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
