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
|
||||
gather_facts: false
|
||||
roles:
|
||||
- mysql_deploy
|
||||
- laravelio_deploy
|
||||
- post_deploy
|
||||
- pre_deploy
|
||||
- mysql_deploy
|
||||
- laravelio_deploy
|
||||
- post_deploy
|
||||
# need to add pre_deploy to pip install kubernetes
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
---
|
||||
# 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
|
||||
name: mysql-service
|
||||
namespace: default
|
||||
register: service_info
|
||||
register: mysql_service_info
|
||||
|
||||
- name: Extract ClusterIP from MySQL service
|
||||
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
|
||||
kubernetes.core.k8s:
|
||||
name: laravelio-config
|
||||
|
@ -29,11 +26,23 @@
|
|||
DB_USERNAME: laraveliouser
|
||||
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
|
||||
kubernetes.core.k8s:
|
||||
namespace: default
|
||||
state: present
|
||||
src: roles/laravelio_deploy/templates/laravelio-deployment.yml
|
||||
wait: yes
|
||||
|
||||
- name: Create laravelio Service
|
||||
kubernetes.core.k8s:
|
||||
|
@ -42,9 +51,27 @@
|
|||
src: roles/laravelio_deploy/templates/laravelio-service.yml
|
||||
wait: yes
|
||||
|
||||
- name: Seed database
|
||||
kubernetes.core.k8s_exec:
|
||||
# Seed database section
|
||||
|
||||
- name: Get laravelio pod name
|
||||
kubernetes.core.k8s_info:
|
||||
namespace: default
|
||||
pod: laravelio
|
||||
command: "php artisan db:seed"
|
||||
kind: Pod
|
||||
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"
|
||||
|
|
|
@ -8,7 +8,7 @@ metadata:
|
|||
app: laravelio
|
||||
tier: app
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: laravelio
|
||||
ports:
|
||||
|
|
|
@ -17,3 +17,4 @@
|
|||
state: present
|
||||
src: roles/mysql_deploy/templates/mysql-service.yml
|
||||
wait: yes
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ metadata:
|
|||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
storageClassName: local-storage
|
||||
storageClassName: standard-rwo
|
||||
resources:
|
||||
requests:
|
||||
storage: 20Gi
|
||||
|
|
|
@ -7,13 +7,16 @@
|
|||
label_selectors:
|
||||
- "app=laravelio"
|
||||
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
|
||||
delay: 10
|
||||
|
||||
- name: Store app_ip
|
||||
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
|
||||
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