Lab 3 - Server Orchestration with Ansible
Objectifs
Dans ce lab, l’objectif est de tester plusieurs méthodes d’orchestration :
- Orchestration serveur avec Ansible
- Orchestration VM avec Packer + OpenTofu
- Orchestration conteneur avec Docker + Kubernetes
- Orchestration serverless avec AWS Lambda
L’idée est de comprendre les différences entre chaque approche et voir comment gérer le déploiement d’une application de manière progressive et automatisée.
Important : toute l’infrastructure a été déployée dans la région eu-north-1, avec l’AMI : ami-0836abe45b78b6960
Partie 1 – Server Orchestration with Ansible
Step 1 - Set Up the Ansible Environment
Installation de la collection AWS :
ansible-galaxy collection install amazon.awsConfiguration AWS CLI :
aws configureStep 2 - Creating EC2 Instances with Ansible
Déploiement de 3 instances via playbook :
ansible-playbook -v create_ec2_instances_playbook.yml --extra-vars "@sample-app-vars.yml"Step 3 - Configuring Dynamic Inventory
Inventaire dynamique avec :
ansible-inventory -i inventory.aws_ec2.yml --graphStep 4 - Deploying the Sample Node.js Application
Correction du problème de permissions avec :
[defaults]
allow_world_readable_tmpfiles = True
remote_tmp = /tmp/.ansible-${USER}
[ssh_connection]
pipelining = True
Step 5 - Setting Up Nginx as a Load Balancer
Déploiement de Nginx :
ansible-playbook -v create_ec2_instances_playbook.yml --extra-vars "@nginx-vars.yml"
ansible-playbook -v -i inventory.aws_ec2.yml configure_nginx_playbook.ymlRécupération de l’IP publique :
aws ec2 describe-instances --filters "Name=tag:Ansible,Values=nginx_instances" --query "Reservations[*].Instances[*].PublicIpAddress" --output textStep 6 - Implementing Rolling Updates
Rolling update avec :
ansible-playbook -v -i inventory.aws_ec2.yml configure_sample_app_playbook.yml
while true; do curl http://51.20.92.251; sleep 1; donePartie 2 - VM Orchestration with Packer and OpenTofu
Step 1 - Building a VM Image Using Packer
packer build sample-app.pkr.hclStep 2 - Deploying the VM Image Using OpenTofu
tofu init
tofu applyStep 3 - Deploying an Application Load Balancer (ALB)
curl http://sample-app-alb-2045686205.eu-north-1.elb.amazonaws.comStep 4 - Implementing Rolling Updates with ASG Instance Refresh
Nouvelle AMI avec Packer, mise à jour dans main.tf, suivi du changement :
while true; do curl "sample-app-alb-2045686205.eu-north-1.elb.amazonaws.com"; sleep 1; donePartie 3 - Container Orchestration with Docker and Kubernetes
Step 1 - Building and Running the Docker Image Locally
docker build -t sample-app:v1 .
docker run -p 8080:8080 sample-app:v1
curl http://localhost:8080Step 2 - Deploying the Application to a Local Kubernetes Cluster
kubectl apply -f sample-app-deployment.yaml
kubectl get pods
kubectl apply -f sample-app-service.yaml
curl http://localhostStep 3 - Performing a Rolling Update
docker build -t sample-app:v2 .
# Mise à jour du deploymentPartie 4 - Deploying Applications Using Serverless Orchestration with AWS Lambda
Step 1 - Set Up the Working Directory
Step 2 - Create the Lambda Function Code
Step 3 - Create the Main OpenTofu Configuration
Step 4 - Deploy the Lambda Function
tofu init
tofu applyStep 5 - Verify the Lambda Function
Step 6 - Set Up API Gateway to Trigger the Lambda Function
Step 7 - Deploy the API Gateway Configuration
tofu init
tofu applyStep 8 - Test the API Endpoint
Step 9 - Update the Lambda Function
tofu applyStep 10 - Verify the Update
curl https://4w7r0c17mf.execute-api.eu-north-1.amazonaws.comClean Up
tofu destroyConclusion
Ce lab nous a permis de voir plusieurs façons de déployer une application, du serveur classique jusqu’au serverless.
On voit bien l’évolution : au début on gère les machines puis les conteneurs et à la fin on ne gère plus que le code.
Chaque approche a ses avantages selon le besoin mais plus on avance, plus l’infrastructure est abstraite et automatisée.
Ce lab nous a donc permis de mieux comprendre les différences concrètes entre VM, Kubernetes et Lambda.