Skip to content

Web application using Flask and PostgreSQL, orchestrated with Kubernetes and deployed on AWS via CloudFormation, EKS, and ECR. This project showcases modern DevOps practices and cloud deployment, including monitoring with Prometheus and metric visualization with Grafana.

Notifications You must be signed in to change notification settings

albuquerquefabio/kubedev-fake-shop

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fake Shop

Exemplo de aplicação web utilizando Flask, PostgreSQL e Kubernetes. Este projeto foi configurado e implementado com AWS CloudFormation, EKS e ECR para demonstrar práticas modernas de DevOps e implantação em nuvem.

Variável de Ambiente - .env

Criar arquivo .env

# Server
DB_HOST=Host do banco de dados PostgreSQL.

DB_USER=Nome do usuário do banco de dados PostgreSQL.

DB_PASSWORD=Senha do usuário do banco de dados PostgreSQL.

DB_NAME=Nome do banco de dados PostgreSQL.

DB_PORT=Porta de conexão com o banco de dados PostgreSQL.

# Postgre
POSTGRES_DB=Nome do banco de dados PostgreSQL.

POSTGRES_USER=Nome do usuário do banco de dados PostgreSQL.

POSTGRES_PASSWORD=Senha do usuário do banco de dados PostgreSQL.

#Grafana
GF_SECURITY_ADMIN_USER=Nome do usuário do Grafana. String ou Base64
GF_SECURITY_ADMIN_PASSWORD=Senha do usuário do Grafana. String ou Base64

AWS

Instalar AWS CLI (PT-BR)

Configurar

aws configure

AWS CloudFormation

Subir CloudFormation stack

aws cloudformation create-stack --stack-name <stack-name> --template-body file://<path-to-your-yaml-file> --region <your-region>

Atualizar CloudFormation stack existente

aws cloudformation update-stack --stack-name <stack-name> --template-body file://<path-to-your-yaml-file> --region <your-region>

Deletar CloudFormation stack

aws cloudformation delete-stack --stack-name <stack-name> --region <your-region>

AWS EKS

Configurar local kubectl

Rodas o comando após criar o EKS Cluster.

aws eks update-kubeconfig --name <cluster-name> --region us-east-1

Criar node group

aws eks create-nodegroup \
  --cluster-name <cluster-name> \
  --nodegroup-name <nodegroup-name> \
  --subnets <private:subnet-123> <private:subnet-321> \
  # t3a.small | t3a.medium | t3.small | t3.medium
  --instance-types t3a.medium \
  --scaling-config minSize=2,maxSize=4,desiredSize=2 \
  --capacity-type ON_DEMAND \
  --ami-type AL2_x86_64 \
  --node-role <arn:aws:iam::123:role/my-role> \
  # N. Virginia
  --region us-east-1

Deletar EKS Node Group

aws eks delete-nodegroup --cluster-name <cluster-name> --nodegroup-name <nodegroup-name>

Deletar EKS Cluster

aws eks delete-cluster --name <cluster-name>

AWS Extra

AWS ECR

Criar ECR Repository

aws ecr create-repository --repository-name <repository-name> --region <your-region>

Autenticar Docker para ECR

aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<your-region>.amazonaws.com

Montar imagem Docker

docker build -t <repository-name> .

Tag para imagem Docker

docker tag <repository-name>:latest <aws_account_id>.dkr.ecr.<your-region>.amazonaws.com/<repository-name>:latest

Subir imagem Docker para ECR

docker push <aws_account_id>.dkr.ecr.<your-region>.amazonaws.com/<repository-name>:latest

Deletar o ECR Repository

aws ecr delete-repository --repository-name <repository-name> --region <your-region> --force

Erro de token

Caso retorne uma mensagem de falha como ... The security token included in the request is invalid., execute:

unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN

Depois, refaça o passo de configuração da AWS.

Passos de remoção

Os itens a seguir podem gerar cobranças caso permaneçam ativos: CloudFormation, EKS e ECR. Siga o passo a passo para removê-los.

  1. Delete o EKS Node Group.
  2. Delete o EKS Cluster.
  3. Delete o CloudFormation stack.
  4. Delete o ECR Registry. *Caso esteja usando o Repositório ECR da AWS

Deploy

Docker hub

albuquerquefabio/kubedev-fake-shop

Kubernetes

Criar aula-secrets:

kubectl create secret generic aula-secrets --from-env-file=.env
kubectl create secret generic grafana-secrets --from-env-file=.env

Subir pods (deployment | service):

kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/deploy-prometheus.yaml

Detalhes:

kubectl get all
kubectl get service

Remover pods

kubectl delete deployment fake-shop
kubectl delete deployment postgre

kubectl delete service fake-shop
kubectl delete service postgre

kubectl delete secret aula-secrets

About

Web application using Flask and PostgreSQL, orchestrated with Kubernetes and deployed on AWS via CloudFormation, EKS, and ECR. This project showcases modern DevOps practices and cloud deployment, including monitoring with Prometheus and metric visualization with Grafana.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • SCSS 47.9%
  • CSS 38.1%
  • HTML 7.4%
  • Python 5.1%
  • JavaScript 1.1%
  • PHP 0.2%
  • Other 0.2%