checkpoint 2 up and running
This commit is contained in:
parent
c532d498c4
commit
e5ef964dc6
9 changed files with 103 additions and 18 deletions
|
@ -3,7 +3,8 @@
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
roles:
|
roles:
|
||||||
- mysql_deploy
|
- pre_deploy
|
||||||
- laravelio_deploy
|
- mysql_deploy
|
||||||
- post_deploy
|
- laravelio_deploy
|
||||||
|
- post_deploy
|
||||||
# need to add pre_deploy to pip install kubernetes
|
# need to add pre_deploy to pip install kubernetes
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
---
|
|
||||||
# Playbook to undeploy laravel.io and its component
|
# Playbook to undeploy laravel.io and its component
|
||||||
# TO DO
|
---
|
||||||
|
- name: Undeploy Laravelio
|
||||||
|
hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
roles:
|
||||||
|
- undeploy_all
|
||||||
|
|
|
@ -5,15 +5,12 @@
|
||||||
kind: Service
|
kind: Service
|
||||||
name: mysql-service
|
name: mysql-service
|
||||||
namespace: default
|
namespace: default
|
||||||
register: service_info
|
register: mysql_service_info
|
||||||
|
|
||||||
- name: Extract ClusterIP from MySQL service
|
- name: Extract ClusterIP from MySQL service
|
||||||
set_fact:
|
set_fact:
|
||||||
cluster_ip: "{{ service_info.resources[0].spec.clusterIP }}"
|
cluster_ip: "{{ mysql_service_info.resources[0].spec.clusterIP }}"
|
||||||
|
|
||||||
- name: Print ClusterIP
|
|
||||||
debug:
|
|
||||||
var: cluster_ip
|
|
||||||
- name: Create ConfigMap for laravelio
|
- name: Create ConfigMap for laravelio
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
name: laravelio-config
|
name: laravelio-config
|
||||||
|
@ -29,11 +26,23 @@
|
||||||
DB_USERNAME: laraveliouser
|
DB_USERNAME: laraveliouser
|
||||||
DB_PASSWORD: "123456"
|
DB_PASSWORD: "123456"
|
||||||
|
|
||||||
|
- name: Wait for MySQL to be Running
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
|
namespace: default
|
||||||
|
kind: Pod
|
||||||
|
label_selectors:
|
||||||
|
- "app=mysql"
|
||||||
|
register: mysql_pod_info
|
||||||
|
until: mysql_pod_info.resources[0].status.phase == "Running"
|
||||||
|
retries: 60
|
||||||
|
delay: 5
|
||||||
|
|
||||||
- name: Create laravelio Deployment
|
- name: Create laravelio Deployment
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
namespace: default
|
namespace: default
|
||||||
state: present
|
state: present
|
||||||
src: roles/laravelio_deploy/templates/laravelio-deployment.yml
|
src: roles/laravelio_deploy/templates/laravelio-deployment.yml
|
||||||
|
wait: yes
|
||||||
|
|
||||||
- name: Create laravelio Service
|
- name: Create laravelio Service
|
||||||
kubernetes.core.k8s:
|
kubernetes.core.k8s:
|
||||||
|
@ -42,9 +51,27 @@
|
||||||
src: roles/laravelio_deploy/templates/laravelio-service.yml
|
src: roles/laravelio_deploy/templates/laravelio-service.yml
|
||||||
wait: yes
|
wait: yes
|
||||||
|
|
||||||
- name: Seed database
|
# Seed database section
|
||||||
kubernetes.core.k8s_exec:
|
|
||||||
|
- name: Get laravelio pod name
|
||||||
|
kubernetes.core.k8s_info:
|
||||||
namespace: default
|
namespace: default
|
||||||
pod: laravelio
|
kind: Pod
|
||||||
command: "php artisan db:seed"
|
label_selectors:
|
||||||
|
- "app=laravelio"
|
||||||
|
register: laravelio_pod_info
|
||||||
|
when: seed_database is defined and seed_database == "true"
|
||||||
|
|
||||||
|
- name: Extract laravelio pod name
|
||||||
|
set_fact:
|
||||||
|
laravelio_pod_name: "{{ laravelio_pod_info.resources[0].metadata.name }}"
|
||||||
|
|
||||||
|
|
||||||
|
- name: Migrate database
|
||||||
|
command: "kubectl exec -t {{ laravelio_pod_name }} -- php artisan migrate"
|
||||||
|
when: seed_database is defined and seed_database == "true"
|
||||||
|
|
||||||
|
|
||||||
|
- name: Seed database
|
||||||
|
command: "kubectl exec -t {{ laravelio_pod_name }} -- php artisan db:seed"
|
||||||
when: seed_database is defined and seed_database == "true"
|
when: seed_database is defined and seed_database == "true"
|
||||||
|
|
|
@ -8,7 +8,7 @@ metadata:
|
||||||
app: laravelio
|
app: laravelio
|
||||||
tier: app
|
tier: app
|
||||||
spec:
|
spec:
|
||||||
type: LoadBalancer
|
type: LoadBalancer
|
||||||
selector:
|
selector:
|
||||||
app: laravelio
|
app: laravelio
|
||||||
ports:
|
ports:
|
||||||
|
|
|
@ -17,3 +17,4 @@
|
||||||
state: present
|
state: present
|
||||||
src: roles/mysql_deploy/templates/mysql-service.yml
|
src: roles/mysql_deploy/templates/mysql-service.yml
|
||||||
wait: yes
|
wait: yes
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ metadata:
|
||||||
spec:
|
spec:
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
storageClassName: local-storage
|
storageClassName: standard-rwo
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 20Gi
|
storage: 20Gi
|
||||||
|
|
|
@ -7,13 +7,16 @@
|
||||||
label_selectors:
|
label_selectors:
|
||||||
- "app=laravelio"
|
- "app=laravelio"
|
||||||
register: service_info
|
register: service_info
|
||||||
until: service_facts.resources[0].status.loadBalancer.ingress[0].ip is defined
|
until: service_info.resources[0].status.loadBalancer.ingress[0].ip is defined
|
||||||
retries: 60
|
retries: 60
|
||||||
delay: 10
|
delay: 10
|
||||||
|
|
||||||
- name: Store app_ip
|
- name: Store app_ip
|
||||||
set_fact:
|
set_fact:
|
||||||
app_ip: "{{ service_facts.resources[0].status.loadBalancer.ingress[0].ip }}"
|
app_ip: "{{ service_info.resources[0].status.loadBalancer.ingress[0].ip }}"
|
||||||
|
- name: Print app_ip
|
||||||
|
debug:
|
||||||
|
var: app_ip
|
||||||
|
|
||||||
- name: Update app_ip in Inventory
|
- name: Update app_ip in Inventory
|
||||||
lineinfile:
|
lineinfile:
|
||||||
|
|
5
roles/pre_deploy/tasks/main.yml
Normal file
5
roles/pre_deploy/tasks/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
- name: Installing Kubernetes through pip
|
||||||
|
pip:
|
||||||
|
name: kubernetes
|
||||||
|
state: present
|
44
roles/undeploy_all/tasks/main.yml
Normal file
44
roles/undeploy_all/tasks/main.yml
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
---
|
||||||
|
- name: Undeploy laravelio Service
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
namespace: default
|
||||||
|
state: absent
|
||||||
|
src: roles/laravelio_deploy/templates/laravelio-service.yml
|
||||||
|
|
||||||
|
- name: Undeploy laravelio Deployment
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
namespace: default
|
||||||
|
state: absent
|
||||||
|
src: roles/laravelio_deploy/templates/laravelio-deployment.yml
|
||||||
|
|
||||||
|
- name: Undeploy laravelio ConfigMap
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
namespace: default
|
||||||
|
state: absent
|
||||||
|
definition:
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: laravelio-config
|
||||||
|
namespace: default
|
||||||
|
|
||||||
|
- name: Undeploy MySQL Service
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
namespace: default
|
||||||
|
state: absent
|
||||||
|
src: roles/mysql_deploy/templates/mysql-service.yml
|
||||||
|
wait: yes
|
||||||
|
|
||||||
|
- name: Undeploy MySQL Deployment
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
namespace: default
|
||||||
|
state: absent
|
||||||
|
src: roles/mysql_deploy/templates/mysql-deployment.yml
|
||||||
|
|
||||||
|
# add a flag to not delete data
|
||||||
|
- name: Undeploy MySQL Persistent Volume Claim
|
||||||
|
kubernetes.core.k8s:
|
||||||
|
namespace: default
|
||||||
|
state: absent
|
||||||
|
src: roles/mysql_deploy/templates/mysql-pvc.yml
|
||||||
|
|
Loading…
Add table
Reference in a new issue