Refactor Udagram app into Microservices and Deploy FAQ — Udacity

Alvaro Andres Pinzon Cortes
4 min readJan 21, 2020

--

Final expected result:

The Udagram application is working online, hosted in an AWS cluster and users can interact with it.

Frequent student issues

◾️CORS: CORS
Access to XMLHttpRequest at ‘https://s3.amazonaws.com/' from origin ‘http://a699be960decb474d80136f3bed1613d-894180891.us-east-1.elb.amazonaws.com' has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

◾️Not able to edit Cross-origin resource sharing (CORS)

◾️CORS policy error when using the LoadBalancer external IP address

◾️Database connection error in Kubernetes

◾️My pods keeps crashing out. but my docker images run locally and fine.

◾️Unable to upload image

◾️For the HPA themetric for cpu utilization is unknown.

The HPA is important to make your app scalable. Remember that you need to complete these steps:

1. Deploy Metrics Server to your Kubernetes cluster. You can install it by following the instructions here.
2. Create the Deployments
3. Create Horizontal Pod Autoscalers for your applications.

In these guides you can learn how to do this:
- Horizontal Pod Autoscaler — AWS
- How to Configure Kubernetes Horizontal Pod Autoscaler using Metrics Server

These are some relevant posts in the knowledge platform:

- solution 1

- solution 2

- solution 3

- solution 4

- solution 5

- solution 6

◾️Getting error ‘UnhandledPromiseRejectionWarning: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:5432’ when running my container

◾️S3 PutObjectRequest failing with “Access Point ARN AccountID does not match Regex” #2430

◾️In my aws-secret.yaml what is thecredential? Is that the “Secret access key” of my user?

Steps to complete the project

1.1 Follow the getting started instructions in the project description

1.1 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

1.2 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

2 Run the project locally as a Monolithic application

3 Divide the application into microservices

3.1 Create the microservices

3.2 Test with docker compose

3.3 Test the project locally in minikube. Follow this tutorial:

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

4. Build CICD pipeline with Travis

4.1 Create a GitHub repository to store the project and include the link in README.md to the repository for reviewers.

4.2 Add in the Travis pipeline what is necessary to build the image of the application.

4.3 Add in the Travis pipeline what is necessary to push the image to DockerHub using using Travis

5. Create the Kubernetes cluster in AWS

eksctl create cluster --name udagram-cluster --region us-east-1 --managed --nodes 2 --node-type t2.smallaws eks update-kubeconfig --region us-east-1 --name eks-demo-deployment

6. Deploy the microservices to the Aws Kubernetes cluster

Checklist of important steps

  • bucket is public
  • Locally have aws credentials
  • credentials are correctly set
  • Make sure that the “aws configure” command is working well and showing your credentials after setting the environment variables. You need to configure the AWS profile in the config
  • CORS in aws is correct
  • In the environment variables use the bucket’s name and not the ARN
  • CORS in server code is correct
  • Able to do requests using Postman. This is a way to verify
  • Correct reverse proxy configuration
  • Check correct environment variables
  • Use the correct CORS policy and in the right format. It is possible that you use xml and that is not correct.
  • Database can be accessed and a test using postbird works
  • Check the pods of each pod to debug
  • Give some time to the update, sometimes it takes a few minutes to load the update.
  • Use logging to debug
  • The deployment files are well configured and have correct environment variables
  • Use the right resources in AWS with enough size. Use bigger instances, storage and memory
  • The aws user has the correct permissions
  • You need to set resource limits for your deployments
  • convert the credentials in base64

Resources & Links

--

--

No responses yet