This challenge is divided into two parts:
Create a simple REST API using your preferred programming language that does the following:
- It responds to the URL like http://host-ip/ and returns: Hello World, I'm Omar
- responds to the URL like http://host-ip/?n=x and returns n*n
- It responds to the URL like http://host-ip/ip with the IP address of the client making the request and save that IP address on Postgres
- It responds to the URL like http://host-ip/allips with all of the saved IP addresses after retrieving it from Postgres.
- The app is served via a wsgi handler. Like uWSGI
- The Application is Dockerized.
there are several options to deploy the app
in this option we will use sqlite database
- Install Docker
- Clone this repo
git clone https://github.com/omarelsheekh/DevOps-Challenge
- Build the docker image
docker build -t <image name> DevOps-Challenge/app/
- Run the docker image
docker run -e "db_type=sqlite" -dp 5000:5000 -p 9191:9191 <image name>
- Install Docker on all machines
- Install kubectl on machines you will run commands from
- Setup a K8s cluster, you can pick one of these options
- Install helm on machines have kubectl installed
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- Clone this repo
git clone https://github.com/omarelsheekh/DevOps-Challenge
- Build the docker image
docker build -t <image name> DevOps-Challenge/app/
- move to helm-chart directory
cd DevOps-Challenge/helm-chart
- Run the app helm chart
helm install --set app.image=<image name> app .
- warning: if you running it on minikube you have to set affinity to ""
helm install --set app.affinity="" --set postgresql.affinity="" --set app.image=<image name> myapp .
- Verify the IP addresses is set to the ingress:
$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
myapp-app-ingress <none> * 192.168.49.2 80 9m13s
- Verify that the Ingress controller is directing traffic
$ curl 192.168.49.2/
Hello World, I\'m Omar
Using the automation tool (Terraform) prepare a FULLY provisioned environment.
- Provision 3 nodes on Azure, On these 3 nodes deploy:
- The API
- DB Master (PostgreSQL)
- DB Slave (PostgreSQL) and Setup master-slave (streaming replication) PostgreSQL between node 2 and 3.
- Deploying the Dockerized API on the App node
- Install Terraform
- Install azure Cli
- log in to your azure account
- Make Sure that your subscription is active
$ az account list
[
{
"cloudName": "AzureCloud",
"homeTenantId": "f6****22-84be-48a6-b**c-c0*******1f1",
"id": "b7*****1-475c-41a6-a**2-d********f1c",
"isDefault": true,
"managedByTenants": [],
"name": "Azure for Students",
"state": "Enabled",
"tenantId": "f6****22-84be-48a6-b**c-c0*******1f1",
"user": {
"name": "foo@ex.com",
"type": "user"
}
}
]
- Install Ansible
- Clone this repo
git clone https://github.com/omarelsheekh/DevOps-Challenge
- Change your directory to the repo
- Change default variables in variables.tf if you want
Start Building All Infra in One Command
Destroy Infra Whenever you want