Skip to content

Instantly share code, notes, and snippets.

@pranavgaikwad
Last active July 21, 2020 20:40
Show Gist options
  • Save pranavgaikwad/c31834872e46c6e95952a37e7daf7544 to your computer and use it in GitHub Desktop.
Save pranavgaikwad/c31834872e46c6e95952a37e7daf7544 to your computer and use it in GitHub Desktop.
Demo App Deployer

Introduction

deployer.yml deploys or deletes instances of the Parks App demo application on given OpenShift cluster.

Deploying app on the source cluster

Login to your source cluster and store the KUBECONFIG in a file :

export KUBECONFIG=<PATH_TO_OCP3_CONFIG>
oc login ...

Deploy instances of applications :

ansible-playbook deployer.yml -e kubeconfig=<PATH_TO_OCP3_CONFIG> -e ns_count=100

Destroy :

ansible-playbook deployer.yml -e kubeconfig=<PATH_TO_OCP3_CONFIG> -e ns_count=100 -e destroy=true

Cleaning up app from destination cluster

Login to your source cluster and store the KUBECONFIG in a file :

export KUBECONFIG=<PATH_TO_OCP4_CONFIG>
oc login ...

Clean up :

ansible-playbook deployer.yml -e kubeconfig=<PATH_TO_OCP4_CONFIG> -e ns_count=100 -e destroy=true
# how many namespaces to create on the source cluster?
ns_count: 100
# prefix for namespace names
ns_prefix: parks-app
---
- hosts: localhost
connection: local
vars_files:
- ./defaults.yml
tasks:
- when: kubeconfig is not defined
fail:
msg: "`kubeconfig` var not set. Exiting..."
- environment:
KUBECONFIG: "{{ kubeconfig | mandatory }}"
block:
- name: "Ensuring requested resource state"
k8s:
state: "{{ 'absent' if destroy|d(false)|bool else 'present' }}"
definition: "{{ lookup('template', './manifest.yml.j2') }}"
vars:
app_ns: "{{ ns_prefix }}-{{ item }}"
with_sequence: start=1 end={{ ns_count }}
loop_control:
label: "{{ 'Deleting' if destroy|d(false)|bool else 'Creating' }} app in {{ app_ns }}"
---
apiVersion: v1
kind: Namespace
metadata:
name: {{ app_ns }}
---
kind: ImageStream
apiVersion: v1
metadata:
name: restify
namespace: {{ app_ns }}
labels:
app: restify
status:
dockerImageRepository: ''
---
kind: BuildConfig
apiVersion: v1
metadata:
name: restify
namespace: {{ app_ns }}
labels:
app: restify
spec:
triggers:
- type: GitHub
github:
secret: 4Xwu0tyAab90aaoasd88qweAasdaqvjknfrl3qwpo
- type: Generic
generic:
secret: 4Xwu0tyAab90aaoasd88qweAasdaqvjknfrl3qwpo
- type: ConfigChange
- type: ImageChange
imageChange: {}
source:
type: Git
git:
uri: https://github.com/ryanj/restify-mongodb-parks
ref: master
strategy:
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
namespace: openshift
name: nodejs:0.10
output:
to:
kind: ImageStreamTag
name: "restify:latest"
---
kind: DeploymentConfig
apiVersion: v1
metadata:
name: restify
namespace: {{ app_ns }}
labels:
app: restify
spec:
strategy:
resources: {}
triggers:
- type: ConfigChange
- type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- restify
from:
kind: ImageStreamTag
name: "restify:latest"
replicas: 1
selector:
app: restify
deploymentconfig: restify
template:
metadata:
creationTimestamp:
labels:
app: restify
deploymentconfig: restify
spec:
volumes:
- name: "restify-volume-1"
emptyDir: {}
containers:
- name: restify
image: library/restify:latest
ports:
- containerPort: 8080
protocol: TCP
env:
- name: DATABASE_SERVICE_NAME
value: mongodb
- name: MONGODB_DATABASE
value: restify-database
- name: MONGODB_PASSWORD
value: mongo-user-password
- name: MONGODB_USER
value: mongo-user-1
volumeMounts:
- name: "restify-volume-1"
mountPath: "/run"
---
kind: Route
apiVersion: v1
metadata:
name: restify
namespace: {{ app_ns }}
labels:
app: restify
spec:
to:
kind: Service
name: restify
port:
targetPort: '8080'
---
kind: Service
apiVersion: v1
metadata:
name: restify
namespace: {{ app_ns }}
labels:
app: restify
spec:
ports:
- name: 8080-tcp
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: restify
deploymentconfig: restify
---
kind: DeploymentConfig
apiVersion: v1
metadata:
name: mongodb
namespace: {{ app_ns }}
spec:
strategy:
type: Recreate
triggers:
- type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- mongodb-container
from:
kind: ImageStreamTag
name: mongodb:latest
namespace: openshift
- type: ConfigChange
replicas: 1
selector:
name: mongodb
template:
metadata:
labels:
name: mongodb
spec:
containers:
- name: mongodb-container
image: " "
ports:
- containerPort: 27017
protocol: TCP
env:
- name: MONGODB_USER
value: mongo-user-1
- name: MONGODB_PASSWORD
value: mongo-user-password
- name: MONGODB_DATABASE
value: restify-database
- name: MONGODB_ADMIN_PASSWORD
value: moogo-admin-pass
imagePullPolicy: Always
restartPolicy: Always
---
kind: Service
apiVersion: v1
metadata:
name: mongodb
namespace: {{ app_ns }}
spec:
ports:
- name: mongo
protocol: TCP
port: 27017
targetPort: 27017
selector:
name: mongodb
type: ClusterIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment