Testing the project locally in Minikube — Refactor Udagram App into Microservices and Deploy

Prerequisites

Video tutorial

Step by step guide

Follow the getting started instructions in the project description

Please test the bucket and make sure that it works correctly. You can upload an image manually and if you can access the image’s link then the bucket works correctly

Please test the DB and make sure that it works correctly. Try to connect to it from your local machine.

Suppose that this is the DB information

User: appdbuser
DB: postgres
Password: adminadmin

DB URL: andresdb.cwvy79eg4hgs.us-east-1.rds.amazonaws.com

Then, run the following docker container to connect to the postgres db in your local machine (make sure to use your own DB information and credentials❗️)

docker run -it --rm postgres psql -h andresdb.cwvy79eg4hgs.us-east-1.rds.amazonaws.com -d postgres -U appdbuser

Create a cluster in your local machine using Minikube:

minikube start

Create the ConfigMap and the Secrets that will contain the environment variables and credentials. Also, create the backend-user deployment and service

kubectl apply -f env-configmap.yaml
kubectl apply -f aws-secret.yaml
kubectl apply -f env-secret.yaml
kubectl apply -f backend-user-deployment.yaml
kubectl apply -f backend-feed-deployment.yaml

Create the backend-feed deployment and service

kubectl apply -f backend-user-service.yaml
kubectl apply -f backend-feed-service.yaml

List the pods to check that their status is Running. This means that everything worked correctly

Create the reverse proxy deployment and service

kubectl apply -f revereseproxy-deployment.yaml
kubectl apply -f reverseproxy-service.yaml

List the pods to check that their status is Running. This means that everything worked correctly

Now we are going to connect with one of the containers in the back-user pod to test and make sure that it is working ok. The expected response is underlined

Please replace backend-user-bd8f5d75b-ftk2h with the name of your pod that you can see with kubectl get pods

kubectl exec --stdin --tty backend-user-bd8f5d75b-ftk2h  -- /bin/bash//YOU CAN USE THIS COMMAND
curl localhost:8080
//OR THIS COMMAND
curl backend-user:8080

Now we are going to connect with one of the containers in the back-feed pod to test and make sure that it is working ok. The expected response is underlined

Please replace backend-feed-bd8f5d75b-ftk2h with the name of your pod that you can see with kubectl get pods

kubectl exec --stdin --tty backend-feed-bd8f5d75b-ftk2h  -- /bin/bash//YOU CAN USE THIS COMMAND
curl localhost:8080
//OR THIS COMMAND
curl backend-feed:8080

Now we need to expose the reverseproxy using minikube to be able to interact with it in your local machine. You need to use the correct name of the service in the minikube service command

Now that the service is exposed we can interact with it from our browser. Use the URL that the minikube service displayed and add the /api/v0/feed. The expected response is the following:

Now that we have tested the reverse proxy and make sure that it works we are going to deploy all the backend service micro services and the front and micro service.

I had to delete the kubernetes cluster because I created this part of the tutorial on a different day, and now I have to recreate everything. That’s why you’re going to see that some of the steps are going to duplicate.

I'm going assume that you have already created deployments and services for the cluster microservices in minikube. We’ll now use the minikube service functionality to communicate with the reverse proxy service from our local Computer.

In the front and micro service you need to update the apiHost because that one is going to be used by the front end to make requests to the backend.

Build the docker image for the frontend microservice (make sure that you use your own dockerhub repository name):

docker build -t dockerhubuser/frontend .

Push the docker image for the frontend microservice (make sure that you use your own dockerhub repository name):

docker push dockerhubuser/frontend

You can trigger a rolling update by updating the docker image and then with the command `kubectl set image` use the new image as shown in this example. For more information on how to configure and execute a rolling update strategy in kubernetes, please click on the link.

We’ll now use the minikube service functionality to communicate with the frontend microservice from our local machine.

Now we need to update the feed and user back and micro services to allow the origin of the request from the frontend. Otherwise we're going to experience a CORS error.

Update the CORS configuration in the feed backend microservice. Add the underlined line of code with the URL of the frontend:

Build the docker image for the backend-feed microservice (make sure that you use your own dockerhub repository name):

docker build -t dockerhubuser/backend-feed .

Push the docker image for the backend-feed microservice (make sure that you use your own dockerhub repository name):

docker push dockerhubuser/backend-feed

You can trigger a rolling update by updating the docker image and then with the command `kubectl set image` use the new image as shown in this example

Update the CORS configuration in the user backend microservice. Add the underlined line of code with the URL of the frontend:

Build the docker image for the backend-user microservice (make sure that you use your own dockerhub repository name):

docker build -t dockerhubuser/backend-user .

Push the docker image for the backend-user microservice (make sure that you use your own dockerhub repository name):

docker push dockerhubuser/backend-user

You can trigger a rolling update by updating the docker image and then with the command `kubectl set image` use the new image as shown in this example. For more information on how to configure and execute a rolling update strategy in kubernetes, please click on the link.

Now you can access the front end in the broswer and all the functionality is working.

When you finish testing end the minikube cluster

minikube delete

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Why LaTeXise your paper?

Introduction to Datasources in Google App Maker

Cloud Migration best practices -part 5

Barycentric Coordinates

How To Create An Advanced Website Crawler With JMeter

How to use retrofit in Android Studio

How to use Rust to extend Python

Oops! Deleted the Terraform state file. Imported the resource but now it wants to recreate it!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alvaro Andres Pinzon Cortes

Alvaro Andres Pinzon Cortes

More from Medium

Monitoring Setup — Using AWS OpenSearch(ElasticSearch), Logstash

How To Run Microservices On Google Cloud?

Continuous delivery in IBM Cloud — deploying a microservice to Kubernetes in IBM Cloud

Kubernetes setup