This document outlines the deployment process for the Socks Shop application, utilizing Terraform for infrastructure provisioning and Ansible for application deployment and configuration.
Terraform is used to automate the creation of the required AWS resources, including an EKS cluster, a PostgreSQL database, and storage volumes. This ensures a consistent and repeatable infrastructure setup.
main.tf
: This file defines the AWS resources to be provisioned, including:- EKS Cluster: Creates a managed Kubernetes cluster within AWS.
- PostgreSQL Database: Provisions a PostgreSQL database instance for the application's data storage.
- Storage Volumes: Creates EBS volumes for persistent storage of application data.
- Networking: Configures VPC, subnets, security groups, and routing tables for network connectivity.
variables.tf
: Defines variables for configurable settings, allowing customization of the deployment.outputs.tf
: Defines outputs that provide access to important information about the provisioned resources, such as the Kubernetes API endpoint, database connection details, and VPC ID.
- Initialization: Run
terraform init
to initialize the Terraform workspace and download necessary provider plugins. - Deployment: Execute
terraform apply
to provision the infrastructure based on the configuration inmain.tf
. This will create the AWS resources defined in the configuration. - Output Retrieval: Use
terraform output
to retrieve the values of the outputs defined inoutputs.tf
. This information will be used in the Ansible deployment process.
Ansible is used to automate the deployment and configuration of the Socks Shop application within the provisioned Kubernetes cluster.
hosts-inventory.yml
: Defines the inventory of hosts that Ansible will manage. In this case, it includes the Kubernetes API endpoint, retrieved from Terraform outputs.socks-shop.yml
: This Ansible playbook contains tasks for deploying the Socks Shop application:- Namespace Creation: Creates a dedicated Kubernetes namespace for the application.
- Deployment: Deploys the various components of the Socks Shop application as Kubernetes deployments and services.
- Configuration: Configures the application components, including database connection details retrieved from Terraform outputs.
- Ingress Setup: Configures an ingress controller to expose the application to external users.
vault.yml
: This file stores sensitive information, such as database credentials, encrypted using Ansible Vault.
- Inventory Setup: Update the
hosts-inventory.yml
file with the Kubernetes API endpoint retrieved from Terraform outputs. - Playbook Execution: Run
ansible-playbook -i inventory.yml --ask-vault-pass socks-shop.yml
to execute the Ansible playbook. This will deploy the Socks Shop application within the Kubernetes cluster.
Prometheus is used to monitor the health and performance of the Socks Shop application and the Kubernetes cluster.
- Prometheus Operator: Deploys the Prometheus Operator, which manages Prometheus instances and related components.
- Prometheus Instance: Creates a Prometheus instance to scrape metrics from the application and cluster.
- Alertmanager: Configures an Alertmanager to handle alerts generated by Prometheus.
- Service Monitors: Defines service monitors to tell Prometheus which services to scrape metrics from.
- Alerting Rules: Defines rules that trigger alerts when certain conditions are met, such as high request latency or service failures.
- Deployment: Deploy the Prometheus Operator, Prometheus instance, Alertmanager, and service monitors using Ansible.
- Alerting: Configure alerting rules within Prometheus to monitor for critical conditions and send notifications.
+-----------------+
| External Users |
+-----------------+
|
| HTTP Requests
|
+-----------------+
| Ingress Controller |
+-----------------+
|
|
+-----------------+
| Kubernetes Cluster |
+-----------------+
|
|
+-----------------+
| Socks Shop Application |
+-----------------+
|
|
+-----------------+
| PostgreSQL Database |
+-----------------+
|
|
+-----------------+
| Prometheus Server |
+-----------------+
|
|
+-----------------+
| Alertmanager Server |
+-----------------+
|
|
+-----------------+
| Notification Channels |
+-----------------+
This deployment process leverages Terraform and Ansible to automate the creation of infrastructure and the deployment of the Socks Shop application. Prometheus provides comprehensive monitoring and alerting capabilities, ensuring application health and performance. This approach promotes consistency, efficiency, and scalability in the deployment and management of the Socks Shop application.