Skip to content

Commit

Permalink
Sample app update (#11)
Browse files Browse the repository at this point in the history
* Added conditional for adding sample apps

* Add Wordpress with SQL app

* updated yaml files with --- between sections
  • Loading branch information
magic7s authored Jan 25, 2018
1 parent 5d919be commit c1ded75
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deploy_sample_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
become: yes
become_method: sudo
roles:
- sample_apps
- { role: sample_apps, when: deploy_sample_apps }
2 changes: 2 additions & 0 deletions group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ run_bgp_tasks: false
bgp_router_ip: 172.16.1.1
bgp_router_as: 65000
bgp_myas: 65001

deploy_sample_apps: true
3 changes: 3 additions & 0 deletions roles/sample_apps/tasks/PHPGuestbook.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
- name: Remove app if exists
shell: if [ -e /tmp/guestbook.yaml ]; then kubectl --kubeconfig /etc/kubernetes/admin.conf delete -f /tmp/guestbook.yaml; else echo "Existing file not found"; fi

- name: Copy Guestbook YAML to host
template:
src: guestbook.yaml
Expand Down
18 changes: 18 additions & 0 deletions roles/sample_apps/tasks/WordPressSQL.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Remove app if exists
shell: if [ -e /tmp/wordpresssql.yaml ]; then kubectl --kubeconfig /etc/kubernetes/admin.conf delete -f /tmp/wordpresssql.yaml; else echo "Existing file not found"; fi

- name: Copy WordPressSQL YAML to host
template:
src: wordpresssql.yaml
dest: /tmp/wordpresssql.yaml

- name: Create SQL Secret
command: "kubectl --kubeconfig /etc/kubernetes/admin.conf {{ item }}"
with_items:
- "delete secret mysql-pass"
- "create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD"

- name: Deploying Wordpress SQL
command: "kubectl --kubeconfig /etc/kubernetes/admin.conf apply -f /tmp/wordpresssql.yaml"

3 changes: 2 additions & 1 deletion roles/sample_apps/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- import_tasks: PHPGuestbook.yml
- import_tasks: PHPGuestbook.yml
- import_tasks: WordPressSQL.yml
5 changes: 5 additions & 0 deletions roles/sample_apps/templates/guestbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ spec:
# value: env
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
Expand All @@ -52,6 +53,7 @@ spec:
selector:
app: guestbook
tier: frontend
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
Expand Down Expand Up @@ -79,6 +81,7 @@ spec:
memory: 100Mi
ports:
- containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
Expand All @@ -95,6 +98,7 @@ spec:
app: redis
role: master
tier: backend
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
Expand Down Expand Up @@ -133,6 +137,7 @@ spec:
# value: env
ports:
- containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
Expand Down
163 changes: 163 additions & 0 deletions roles/sample_apps/templates/wordpresssql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
kind: PersistentVolume
apiVersion: v1
metadata:
name: wp-pv-volume1
labels:
app: wordpress
type: local
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp/wordpress-data1"
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: wp-pv-volume2
labels:
app: wordpress
type: local
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp/wordpress-data2"
---
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: frontend
spec:
containers:
- image: wordpress:4.8-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wp-pv-claim

0 comments on commit c1ded75

Please sign in to comment.