Skip to content

Commit

Permalink
Added stateless app guestbook with redis (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
magic7s authored Jan 25, 2018
1 parent bf159a4 commit 5d919be
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 1 deletion.
7 changes: 7 additions & 0 deletions deploy_sample_apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- name: Deploy Sample Applications
hosts: master
remote_user: "{{ ansible_remote_user }}"
become: yes
become_method: sudo
roles:
- sample_apps
9 changes: 9 additions & 0 deletions roles/sample_apps/tasks/PHPGuestbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Copy Guestbook YAML to host
template:
src: guestbook.yaml
dest: /tmp/guestbook.yaml

- name: Deploying PHP Guestbook application with Redis
command: "kubectl --kubeconfig /etc/kubernetes/admin.conf apply -f /tmp/guestbook.yaml"

1 change: 1 addition & 0 deletions roles/sample_apps/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- import_tasks: PHPGuestbook.yml
150 changes: 150 additions & 0 deletions roles/sample_apps/templates/guestbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: frontend
spec:
selector:
matchLabels:
app: guestbook
tier: frontend
replicas: 3
template:
metadata:
labels:
app: guestbook
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google-samples/gb-frontend:v4
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
# Using `GET_HOSTS_FROM=dns` requires your cluster to
# provide a dns service. As of Kubernetes 1.3, DNS is a built-in
# service launched automatically. However, if the cluster you are using
# does not have a built-in DNS service, you can instead
# instead access an environment variable to find the master
# service's host. To do so, comment out the 'value: dns' line above, and
# uncomment the line below:
# value: env
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# comment or delete the following line if you want to use a LoadBalancer
type: NodePort
# if your cluster supports it, uncomment the following to automatically create
# an external load-balanced IP for the frontend service.
# type: LoadBalancer
ports:
- port: 80
selector:
app: guestbook
tier: frontend
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: redis-master
spec:
selector:
matchLabels:
app: redis
role: master
tier: backend
replicas: 1
template:
metadata:
labels:
app: redis
role: master
tier: backend
spec:
containers:
- name: master
image: k8s.gcr.io/redis:e2e # or just image: redis
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
app: redis
role: master
tier: backend
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
role: master
tier: backend
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: redis-slave
spec:
selector:
matchLabels:
app: redis
role: slave
tier: backend
replicas: 2
template:
metadata:
labels:
app: redis
role: slave
tier: backend
spec:
containers:
- name: slave
image: gcr.io/google_samples/gb-redisslave:v1
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
# Using `GET_HOSTS_FROM=dns` requires your cluster to
# provide a dns service. As of Kubernetes 1.3, DNS is a built-in
# service launched automatically. However, if the cluster you are using
# does not have a built-in DNS service, you can instead
# instead access an environment variable to find the master
# service's host. To do so, comment out the 'value: dns' line above, and
# uncomment the line below:
# value: env
ports:
- containerPort: 6379
apiVersion: v1
kind: Service
metadata:
name: redis-slave
labels:
app: redis
role: slave
tier: backend
spec:
ports:
- port: 6379
selector:
app: redis
role: slave
tier: backend
3 changes: 2 additions & 1 deletion site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
- kubeadm
- worker

- import_playbook: contiv_network_configuration.yml
- import_playbook: contiv_network_configuration.yml
- import_playbook: deploy_sample_apps.yml

0 comments on commit 5d919be

Please sign in to comment.