Skip to content
Snippets Groups Projects
Commit bb0e5270 authored by kevineri.bonga's avatar kevineri.bonga
Browse files

cours added

parent b6b235d7
No related branches found
No related tags found
No related merge requests found
File deleted
File added
File added
---
- name: Update apt cache
apt:
update_cache: yes
- name: Install Docker dependencies
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
- name: Add Docker repository
apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
state: present
- name: Install Docker
apt:
name: docker-ce
state: present
update_cache: yes
- name: Start and enable Docker
systemd:
name: docker
state: started
enabled: yes
\ No newline at end of file
---
- name: Provision KinD and deploy MetalLB
hosts: "{{ target_host | default('testserver') }}"
become: True
- name: Provision KinD cluster and deploy a load-balanced app
hosts: testserver
become: true
vars:
kind_version: "v0.20.0"
kubectl_version: "stable"
metallb_version: "v0.13.7"
delete_existing_cluster: true # flag pour option destroy cluster ou pas
tasks:
- name: Install necessary packages
block:
- name: Update apt cache
apt:
update_cache: yes
- name: Install required packages
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
- name: Install KinD
shell: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind
args:
creates: /usr/local/bin/kind
- name: S assurer que le repertoire de destinatin existe
file:
path: /home/terraform
state: directory
mode: '0755'
- name: Copier le fichier de configuration KinD
copy:
src: "manifests/kind-config.yaml"
dest: "/home/terraform/kind-config.yaml"
notify:
- Delete KinD cluster
- Create KinD cluster
- Install MetalLB
- Deploy HTTP-echo application
- name: Install Kubectl
- name: Supprimer le cluster KinD existant (si nécessaire)
shell: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl
args:
creates: /usr/local/bin/kubectl
if kind get clusters | grep -q "kind"; then
kind delete cluster
sleep 30
fi
when: delete_existing_cluster # destroy cluster si deja un présent
register: cluster_deletion
notify: Delete KinD cluster
- name: Configure KinD cluster
- name: Créer le cluster KinD
shell: |
kind create cluster --name mycluster
args:
creates: /root/.kube/config
set -o errexit
cloud-init status --wait
sleep 30
kind create cluster --config /home/terraform/kind-config.yaml
sleep 30
register: kind_creation
ignore_errors: yes
notify: Create KinD cluster
- name: Configure LoadBalancer service
block:
- name: Copy MetalLB configuration
- name: Copier le fichier de configuration MetalLB
copy:
src: files/metallb-native.yml
dest: /root/metallb-native.yml
src: "manifests/metallb-config.yaml"
dest: "/home/terraform/metallb-config.yaml"
notify: Deploy MetalLB configuration
- name: Apply MetalLB configuration
- name: Installer MetalLB
shell: |
kubectl apply -f /root/metallb-native.yml
args:
creates: /root/metallb-applied
cloud-init status --wait
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml
sleep 30
kubectl apply -f /home/terraform/metallb-config.yaml
sleep 30
register: metallb_deployment
ignore_errors: yes
notify: Deploy HTTP-echo application
- name: Check if KinD cluster exists
shell: |
kind get clusters | grep mycluster
register: kind_cluster_check
changed_when: false
failed_when: kind_cluster_check.rc != 0
- name: Copier le fichier de déploiement HTTP-echo
copy:
src: "manifests/lb-deployment.yaml"
dest: "/home/terraform/lb-deployment.yaml"
notify: Deploy HTTP-echo application
- name: Rebuild KinD cluster
- name: Déployer l'application HTTP-echo et le service LoadBalancer
shell: |
kind delete cluster --name mycluster && kind create cluster --name mycluster
when: kind_cluster_check.rc != 0
notify: Rebuild KinD cluster
cloud-init status --wait
sleep 30
kubectl apply -f /home/terraform/lb-deployment.yaml
sleep 30
register: http_echo_deployment
changed_when: "'deployment.apps/http-echo' in http_echo_deployment.stdout"
- name: Delete KinD cluster
shell: |
kind delete cluster --name mycluster
tags: delete_cluster
- name: Debug HTTP-echo deployment
debug:
msg: "HTTP-echo deployment status: {{ http_echo_deployment.stdout }}"
- name: Debug MetalLB deployment
debug:
msg: "MetalLB deployment status: {{ metallb_deployment.stdout }}"
- name: Debug KinD cluster creation
debug:
msg: "KinD cluster creation status: {{ kind_creation.stdout }}"
handlers:
- name: Rebuild KinD cluster
shell: |
kind delete cluster --name mycluster && kind create cluster --name mycluster
- name: Delete KinD cluster
command: kind delete cluster
- name: Deploy MetalLB
shell: |
kubectl apply -f /root/metallb-native.yml
notify: Expose LoadBalancer IP
- name: Create KinD cluster
command: kind create cluster --config /home/terraform/kind-config.yaml
- name: Expose LoadBalancer IP
- name: Install MetalLB
shell: |
socat TCP-LISTEN:80,fork TCP:$(kubectl get svc -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'):80
\ No newline at end of file
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.10/config/manifests/metallb-native.yaml
sleep 30
kubectl apply -f /home/terraform/metallb-config.yaml
sleep 30
- name: Deploy MetalLB configuration
command: kubectl apply -f /home/terraform/metallb-config.yaml
- name: Deploy HTTP-echo application
command: kubectl apply -f /home/terraform/lb-deployment.yaml
\ No newline at end of file
---
- name: Complete setup and deployment
hosts: all
become: True
tasks:
- name: Include Docker installation tasks
include_tasks: install_docker.yml
- name: Include KinD and MetalLB provisioning tasks
include_tasks: kind-metallb.yml
- name: Include HTTP-Echo deployment tasks
include_tasks: deploy_http_echo.yml
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment