This application simplies the access to the covid 19 stats of the world (stats for each country).
This application is used to implement all the knowledge acquired on the Cloud DevOps Engineer
Nano Degree on Udacity. The app has a simple api with two endpoints, the app is built it on top of
Python using Flask
and BeautifulSoup 4
(to scrape the data).
API URL: <your-api-url>
(see the Verifying section to get the url of your api).
Endpoints | Path | Description |
---|---|---|
GET | / |
Returns a Hello World! message with the current state of the app (blue or green ). |
GET | /world-stats |
Returns covid stats of the world. |
PROJECT STRUCTURE
File Name | Description |
---|---|
├── code/ |
This directory contains the Python Flask app and Tests |
├── capstone/ |
Python Flask App. |
├── tests/ |
Tests for the Python Flask App. |
├── .coveragerc |
Python Coverage configuration file. |
├── requirements-ci.txt |
Python dependencies file for Continuous Integration (CI). |
├── requirements-dev.txt |
Python dependencies file for development. |
├── requirements.txt |
Python dependencies file for production. |
├── run.py |
Python script to run the application. |
└── tox.ini |
Flask8 configuration file. |
├── infra/ |
This directory contains the files for docker and kubernetes. |
├── docker/ |
Docker files for blue and green images. |
├── k8s/ |
Kubernetes files for blue and green deployments. |
└── server.yaml |
Template to create the cluster on Amazon EKS using EKSCTL. |
├── nginx/ |
This directory contains the files for a custom NGINX configuration. |
├── screenshots/ |
This directory contains the screenshots for the project validation. |
├── .editorconfig |
Configuration file for editorconfig. |
├── .gitignore |
Configuration file for gitignore. |
├── Jenkinsfile |
Configuration file for Jenkins Pipelines. |
├── Makefile |
Set of custom scripts. |
├── README.md |
Description of the app. |
└── TODO.md |
Project TODO. |
- AWS CLI: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
- AWS IAM Roles for EKS: https://docs.aws.amazon.com/eks/latest/userguide/security_iam_service-with-iam.html
- Jenkins: https://www.jenkins.io/download/
- Docker: https://docs.docker.com/engine/install/
- Kubernetes: https://kubernetes.io/es/docs/tasks/tools/install-kubectl/
- EKSCTL: https://eksctl.io/introduction/#installation
Note: Jenkins needs Java to run. To install Java for jenkins run this command:
sudo apt install default-jdk -y
(only Debian distros)
To create a cluster you can use the following command.
$ eksctl create cluster -f ./infra/eks/cluster.yaml
Note: You can create the cluster manually following this guide: https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html
To create/update a Kubernetes config (kubeconfig) you can use following command.
$ aws eks --region us-east-1 update-kubeconfig --name capstone-cluster
Note: Read more about kubeconfig files for EKS on: https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html
Plugins
- AWS Pipeline: https://plugins.jenkins.io/pipeline-aws
- Aqua MicroScanner: https://plugins.jenkins.io/aqua-microscanner/
- BlueOcean: https://plugins.jenkins.io/blueocean/, https://plugins.jenkins.io/blueocean-executor-info/
Credentials
- Docker (Steps):
- ➡️ Jenkins (Dashboard)
- ➡️ Manage Jenkins
- ➡️ Configure System
- ➡️ Declarative Pipeline (Docker)
- Kubernetes Config File (Steps):
- ➡️ Jenkins (Dashboard)
- ➡️ Job (github repo)
- ➡️ Credentials
- ➡️ Store scoped to
<github-repo>
- ➡️ Global
- ➡️ Add credentials
- Kind:
Secret Text
- ID:
k8s-confige-file
- Secret:
/path/to/your/kubeconfig-file
(absolute paths) e.g:/home/ubuntu/.kube/kubeconfig
- Kind:
- AWS (Steps):
- ➡️ Jenkins (Dashboard)
- ➡️ Job (github repo)
- ➡️ Credentials
- ➡️ Store scoped to
<github-repo>
- ➡️ Global
- ➡️ Add credentials
- Kind:
AWS Credentials
- ID:
aws-creds
- Fill the other fields.
- Kind:
Pipelines
To create a pipeline using BlueOcean
follow this guide: https://www.jenkins.io/doc/book/blueocean/creating-pipelines/
Automate deploys
You can trigger the deployments just pushing update the right branch. If you want to a blue deployment
push your
changes to the blue branch
.
Manual deploys
You can trigger manual deploy using the following command:
$ kubectl apply -f ./infra/k8s/deployments/blue.yaml
$ kubectl apply -f ./infra/k8s/services/blue.yaml
or
$ kubectl apply -f ./infra/k8s/deployments/blue.yaml -f ./infra/k8s/services/blue.yaml
Note: This step require to access to your ec2 instance before. Check the Verifying section to get help.
To connect to your EC2 instance follow this guide: https://docs.aws.amazon.com/quickstarts/latest/vmlaunch/step-2-connect-to-instance.html
To get the external ip of our service you can use the following command:
$ kubectl get services -l app=capstone --output jsonpath='{.items[].status.loadBalancer.ingress[].hostname}'
With the link you can access to the app. If all is working yo can see a message like this:
{"message":"Hello GREEN APP!"}
or
{"message":"Hello BLUE APP!"}
A big thanks to
- Udacity
- Raul Hugo @RaulHugo