omarelsheekh / DevOps-Challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DevOps-Challenge

This challenge is divided into two parts:

Part-1: Programming

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.

Part-2: Deployment

there are several options to deploy the app

in this option we will use sqlite database

  1. Install Docker
  2. Clone this repo
git clone https://github.com/omarelsheekh/DevOps-Challenge
  1. Build the docker image
docker build -t <image name> DevOps-Challenge/app/
  1. Run the docker image
docker run -e "db_type=sqlite" -dp 5000:5000 -p 9191:9191 <image name>
  1. Install Docker on all machines
  2. Install kubectl on machines you will run commands from
  3. Setup a K8s cluster, you can pick one of these options
  4. Install helm on machines have kubectl installed
    curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
  5. Clone this repo
    git clone https://github.com/omarelsheekh/DevOps-Challenge
  6. Build the docker image
    docker build -t <image name> DevOps-Challenge/app/
  7. move to helm-chart directory
    cd DevOps-Challenge/helm-chart
  8. 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 .
  9. 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
  1. 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.

This automation should:

  • Provision 3 nodes on Azure, On these 3 nodes deploy:
    1. The API
    2. DB Master (PostgreSQL)
    3. DB Slave (PostgreSQL) and Setup master-slave (streaming replication) PostgreSQL between node 2 and 3.
  • Deploying the Dockerized API on the App node

Getting Started

  1. Install Terraform
  2. Install azure Cli
  3. log in to your azure account
    az login
  4. 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"
        }
      }
    ]
  5. Install Ansible
  6. Clone this repo
    git clone https://github.com/omarelsheekh/DevOps-Challenge
  7. Change your directory to the repo
    cd DevOps-Challenge
  8. Change default variables in variables.tf if you want

Start Building All Infra in One Command

./create-infra.sh

Destroy Infra Whenever you want

./destroy-infra.sh

About


Languages

Language:HCL 77.7%Language:Shell 11.3%Language:Python 9.8%Language:Dockerfile 1.2%