{"id":16143124,"url":"https://github.com/johnbedeir/devops_zero_to_hero","last_synced_at":"2025-03-18T17:31:13.067Z","repository":{"id":248381399,"uuid":"828526297","full_name":"johnbedeir/DevOps_Zero_To_Hero","owner":"johnbedeir","description":"DevOps_Zero_To_Hero repository! This project is designed to guide you through the journey of mastering DevOps practices, starting from a simple Python Flask application and progressively moving through various stages. The project begins with running the application locally, then to Docker, Docker Compose, Kubernetes, and then to the cloud.","archived":false,"fork":false,"pushed_at":"2024-09-03T14:00:18.000Z","size":491,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T22:24:37.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnbedeir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-14T12:23:00.000Z","updated_at":"2025-03-03T00:40:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"b0c187ad-b131-473d-89ec-a57d5e1a20ee","html_url":"https://github.com/johnbedeir/DevOps_Zero_To_Hero","commit_stats":null,"previous_names":["johnbedeir/devops_zero_to_hero"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FDevOps_Zero_To_Hero","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FDevOps_Zero_To_Hero/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FDevOps_Zero_To_Hero/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FDevOps_Zero_To_Hero/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnbedeir","download_url":"https://codeload.github.com/johnbedeir/DevOps_Zero_To_Hero/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244269471,"owners_count":20426229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T00:08:41.291Z","updated_at":"2025-03-18T17:31:12.771Z","avatar_url":"https://github.com/johnbedeir.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DevOps Zero to Hero\n\n## [Watch YouTube Video Here](https://www.youtube.com/watch?v=Yk_wAh57_YU)\n\n\u003cimg src=imgs/zero-to-hero-cover.png\u003e\n\n## Python Flask Application\n\nDevOps_Zero_To_Hero repository! This project is designed to guide you through the journey of mastering DevOps practices, starting from a simple Python Flask application and progressively moving through various stages. The project begins with running the application locally, then to Docker, Docker Compose, Kubernetes, and then to the cloud.\n\n## Prerequisites\n\n- Python 3.9 or higher\n- pip (Python package installer)\n- Docker\n\n## Running the Application Locally\n\n1. Clone the repository files to your local machine.\n2. Navigate to the project directory.\n3. Install the required Python packages using `pip`:\n\n   ```sh\n   pip3 install -r requirements.txt\n   ```\n\n4. Run the Flask application:\n\n   ```sh\n   python3 app.py\n   ```\n\n5. Open your web browser and go to `http://127.0.0.1:5000`. You should see \"Hello, Docker with Python!\".\n\n## Running the Application with Docker\n\n### Building the Docker Image\n\n1. Make sure you have Docker installed on your machine.\n2. Navigate to the project directory where the `Dockerfile` is located.\n3. Build the Docker image using the following command:\n\n   ```sh\n   docker build -t zero-to-hero-img .\n   ```\n\n### Running the Docker Container\n\nYou can run the Docker container using the built image. There are two options for port mapping:\n\n1. **Default Port (5000:5000)**\n\n   ```sh\n   docker run -d --name zero-to-hero-container -p 5000:5000 zero-to-hero-img\n   ```\n\n2. **Custom Port (e.g., 8083:5000)**\n\n   ```sh\n   docker run -d --name zero-to-hero-container -p 8083:5000 zero-to-hero-img\n   ```\n\n### Accessing the Application\n\n- If you used the default port mapping (`5000:5000`), open your web browser and go to `http://127.0.0.1:5000`.\n- If you used a custom port mapping (e.g., `8083:5000`), open your web browser and go to `http://127.0.0.1:8083`.\n\nYou should see \"Hello, Docker with Python!\".\n\n### Stopping and Removing the Container\n\nTo stop the running container, use:\n\n```sh\ndocker stop zero-to-hero-container\n```\n\nTo remove the container, use:\n\n```sh\ndocker rm zero-to-hero-container\n```\n\nTo remove the docker image, use:\n\n```sh\ndocker rmi zero-to-hero-img\n```\n\n## Automating Docker Container with Ansible\n\nTo further streamline the process of building and running the Docker container, you can use the following Ansible playbook `playbook.yml`. This playbook automates stopping and removing any existing containers and images, building a new Docker image, tagging and pushing it to Docker Hub, and finally running the container.\n\n### Running the Playbook\n\n1. Ensure you have Ansible installed on your machine.\n2. Save the above playbook to a file named `playbook.yml`.\n3. Run the playbook using the following command:\n\n   ```sh\n   ansible-playbook playbook.yml\n   ```\n\nThis playbook simplifies the process of managing your Docker container by automating the repetitive tasks, allowing you to focus on development and deployment.\n\n## Automating Docker Container Management with Shell Scripts\n\nIn addition to using Ansible, you can also automate the process of managing your Docker container using shell scripts. Below are two scripts: one for cleaning up existing Docker containers and images, and another for rebuilding and running the Docker container.\n\n### Shell Scripts\n\n#### `cleanup.sh`\n\nThe `cleanup.sh` script stops and removes any existing Docker containers and images, delete namespace and stop minikube.\n\n#### `build.sh`\n\nThe `build.sh` script stops and removes any existing Docker containers and images, builds a new Docker image from the Dockerfile, push the docker image to Docker Registry, start minikube, create namespace and deploy the application.\n\n### Running the Scripts\n\nMake sure the scripts are executable by running the following commands:\n\n```sh\nchmod +x cleanup.sh\nchmod +x build.sh\n```\n\n3. Run the cleanup script to remove any existing containers and images:\n\n   ```sh\n   ./cleanup.sh\n   ```\n\n4. Run the rebuild script to build the Docker image and run the container:\n\n   ```sh\n   ./build.sh\n   ```\n\nThese scripts provide a straightforward and efficient way to manage your Docker containers and images, ensuring that you can quickly clean up and rebuild your application environment as needed.\n\n---\n\n## Deploying the Application on Minikube Using Kubernetes\n\nIn this section, we will deploy the `DevOps Zero to Hero` application on Minikube using Kubernetes manifest files located in the `k8s` directory. The deployment will consist of a Kubernetes Deployment and a Service that exposes the application.\n\n### Prerequisites\n\n- Minikube installed on your machine.\n- kubectl configured to interact with your Minikube cluster.\n\n### Steps to Deploy\n\n1. **Start Minikube**\n\n   First, start Minikube if it isn't already running:\n\n   ```sh\n   minikube start\n   ```\n\n2. **Navigate to the Kubernetes Manifests Directory**\n\n   Change your directory to the `k8s` folder where the Kubernetes manifests (`deployment.yml` and `service.yml`) are stored.\n\n   ```sh\n   cd k8s\n   ```\n\n3. **Create a Namespace**\n\n   It's a good practice to deploy your resources into a specific namespace. Create a namespace named `zero-to-hero`:\n\n   ```sh\n   kubectl create namespace zero-to-hero\n   ```\n\n4. **Deploy the Application**\n\n   Apply the deployment manifest to create the Deployment:\n\n   ```sh\n   kubectl apply -f deployment.yml -n zero-to-hero\n   ```\n\n   This command will deploy two replicas of the `zero-to-hero` application using the Docker image `triple3a/zero-to-hero:latest`.\n\n5. **Expose the Application with a Service**\n\n   Next, apply the service manifest to create a Service that exposes the application on a NodePort:\n\n   ```sh\n   kubectl apply -f service.yml -n zero-to-hero\n   ```\n\n   The service will expose the application on a NodePort, allowing you to access it through Minikube's IP address.\n\n6. **Access the Application**\n\n   To access the application, first, retrieve the URL using the following command:\n\n   ```sh\n   minikube service zero-to-hero-service -n zero-to-hero --url\n   ```\n\n   The command will output a URL that you can open in your web browser. This URL will direct you to the `zero-to-hero` application running inside the Minikube cluster.\n\n### Managing the Deployment with k9s\n\n`k9s` is a powerful terminal-based UI to manage your Kubernetes clusters. It simplifies the management of resources within your cluster, including deployments, services, and more.\n\n#### Accessing Your Cluster with k9s\n\n1. **Start k9s**\n\n   Launch `k9s` by simply typing the following command in your terminal:\n\n   ```sh\n   k9s\n   ```\n\n2. **Switch to the `zero-to-hero` Namespace**\n\n   By default, `k9s` shows resources in the `default` namespace. To switch to the `zero-to-hero` namespace, type:\n\n   ```sh\n   :zero-to-hero\n   ```\n\n   This will filter the view to only show resources within the `zero-to-hero` namespace.\n\n#### Scaling the Deployment\n\nTo scale your `zero-to-hero` deployment:\n\n1. Navigate to the `Deployments` view by selecting `Deployments` from the `k9s` menu or by typing `deploy` in the command bar.\n2. Select the `zero-to-hero-deployment` by navigating to it using the arrow keys.\n3. Press `S` to scale the deployment. You will be prompted to enter the desired number of replicas.\n4. Enter the new replica count and press `Enter`.\n\n#### Updating the Deployment\n\nIf you need to update the Docker image used by your deployment:\n\n1. Select the `zero-to-hero-deployment` in the `Deployments` view.\n2. Press `E` to edit the deployment manifest directly in `k9s`.\n3. Navigate to the `spec` section and update the `image` field to the new Docker image version.\n4. Save and exit the editor. `k9s` will automatically apply the changes to your cluster.\n\n#### Deleting the Deployment and Service\n\nTo delete the `zero-to-hero` deployment and service:\n\n1. Navigate to the `Deployments` view and select `zero-to-hero-deployment`.\n2. Press `D` to delete the deployment.\n3. Confirm the deletion when prompted.\n\n   Repeat the process for the `Services` view to delete the `zero-to-hero-service`.\n\n   Alternatively, you can delete all resources in the `zero-to-hero` namespace by selecting the namespace in `k9s` and pressing `ctrl+d`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnbedeir%2Fdevops_zero_to_hero","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnbedeir%2Fdevops_zero_to_hero","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnbedeir%2Fdevops_zero_to_hero/lists"}