Skip to content

Commit

Permalink
Add helm
Browse files Browse the repository at this point in the history
  • Loading branch information
themoosman committed Dec 2, 2020
1 parent 066b30f commit 4832f40
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .helm/python-crash-me/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
name: python-crash-me
description: A chart for the python-crash-me app
version: 1.0.0
31 changes: 31 additions & 0 deletions .helm/python-crash-me/templates/buildconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- if .Values.build_ns }}
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
annotations:
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: {{ .Release.Name }}
name: {{ .Release.Name }}
spec:
failedBuildsHistoryLimit: 5
nodeSelector: null
output:
to:
kind: ImageStreamTag
name: {{ .Release.Name }}:latest
runPolicy: Serial
source:
git:
uri: {{ .Values.git_uri }}
ref: {{ .Values.git_ref }}
type: Git
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: {{ .Values.base_is_name }}
namespace: openshift
type: Source
successfulBuildsHistoryLimit: 5
{{- end }}
77 changes: 77 additions & 0 deletions .helm/python-crash-me/templates/deploymentconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
generation: 1
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: {{ .Release.Name }}
name: {{ .Release.Name }}
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
app: {{ .Release.Name }}
deploymentconfig: {{ .Release.Name }}
strategy:
activeDeadlineSeconds: 21600
rollingParams:
intervalSeconds: 1
maxSurge: 25%
maxUnavailable: 25%
timeoutSeconds: 600
updatePeriodSeconds: 1
type: Rolling
template:
metadata:
annotations:
labels:
app: {{ .Release.Name }}
deploymentconfig: {{ .Release.Name }}
spec:
containers:
- image: {{ .Release.Name }}
imagePullPolicy: Always
env:
- name: DEPLOY_ENV
value: {{ .Values.environment }}
livenessProbe:
exec:
command:
- cat
- /tmp/status.up
failureThreshold: 1
initialDelaySeconds: 25
periodSeconds: 1
successThreshold: 1
timeoutSeconds: 1
name: {{ .Release.Name }}
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 8080
scheme: HTTP
initialDelaySeconds: 1
periodSeconds: 25
successThreshold: 1
timeoutSeconds: 1
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
terminationGracePeriodSeconds: 30
test: false
triggers:
- type: ImageChange
imageChangeParams:
automatic: false
containerNames:
- {{ .Release.Name }}
from:
kind: ImageStreamTag
name: {{ .Release.Name }}:latest
namespace: {{ .Values.image_namespace }}
10 changes: 10 additions & 0 deletions .helm/python-crash-me/templates/imagestream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: {{ .Release.Name }}
name: {{ .Release.Name }}
spec:
lookupPolicy:
local: false
20 changes: 20 additions & 0 deletions .helm/python-crash-me/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if not .Values.build_ns }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
creationTimestamp: null
labels:
template: {{ .Release.Name }}
name: {{ .Release.Name }}-edit-{{ .Values.environment }}
namespace: {{ .Values.image_namespace }}
groupNames: null
userNames: null
subjects:
- kind: Group
apiGroup: rbac.authorization.k8s.io
name: system:serviceaccounts:{{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: 'system:image-puller'
{{- end }}
17 changes: 17 additions & 0 deletions .helm/python-crash-me/templates/route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: {{ .Release.Name }}
name: {{ .Release.Name }}
spec:
port:
targetPort: 8080-tcp
tls:
termination: edge
to:
kind: Service
name: {{ .Release.Name }}
weight: 100
wildcardPolicy: None
18 changes: 18 additions & 0 deletions .helm/python-crash-me/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ .Release.Name }}
app.kubernetes.io/name: {{ .Release.Name }}
name: {{ .Release.Name }}
spec:
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: {{ .Release.Name }}
deploymentconfig: {{ .Release.Name }}
sessionAffinity: None
type: ClusterIP
3 changes: 3 additions & 0 deletions .helm/python-crash-me/values-qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build_ns: false
environment: qa
image_namespace: python-crash-me-dev
6 changes: 6 additions & 0 deletions .helm/python-crash-me/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build_ns: true
git_uri: https://github.com/themoosman/ocp-python-crash-me.git
git_ref: master
base_is_name: python:3.8-ubi8
environment: dev
image_namespace: python-crash-me-dev
4 changes: 2 additions & 2 deletions .ocp/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ parameters:
value: "master"
- name: IMAGE_NAME
description: The name of the image.
value: py-crash-me
value: python-crash-me
required: true
- name: IMAGE_VERSION
description: The version of the images to use.
Expand All @@ -58,7 +58,7 @@ parameters:
required: true
- name: APP_NAME
description: Application name.
value: py-crash-me
value: python-crash-me
required: true
- name: BASE_IS_NAME
description: Name of the application base imaagestream.
Expand Down
8 changes: 4 additions & 4 deletions .ocp/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ objects:
- cat
- /tmp/status.up
failureThreshold: 1
initialDelaySeconds: 45
initialDelaySeconds: 25
periodSeconds: 1
successThreshold: 1
timeoutSeconds: 1
Expand Down Expand Up @@ -158,7 +158,7 @@ objects:
parameters:
- name: IMAGE_NAME
description: The name of the image.
value: py-crash-me
value: python-crash-me
required: true
- name: IMAGE_VERSION
description: The version of the images to use.
Expand All @@ -171,12 +171,12 @@ parameters:
required: true
- name: APP_NAME
description: Application name.
value: py-crash-me
value: python-crash-me
required: true
- description: Name of a service account that can deploy to this project
name: SA_NAME
required: true
value: py-crash-sa
value: python-crash-sa
- description: Test ENV Var
name: ENVIRONMENT
required: true
48 changes: 39 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,62 @@ To deploy this sample Python web application from the OpenShift use the provided

Template parameters can be found here. https://github.com/themoosman/ocp-python-crash-me/blob/master/.ocp/deployment.yaml#L155-L176


### The OCP Template Way
```
#Create the DEV project
oc new-project py-crash-me-dev
oc new-project python-crash-me-dev
#To deploy the build components
oc process -f build.yaml -p NAMESPACE=py-crash-me-dev | oc create -f -
oc process -f build.yaml -p NAMESPACE=python-crash-me-dev | oc create -f -
#Create the DEV deployment resources
oc process -f deployment.yaml -p NAMESPACE=py-crash-me-dev -p IMAGE_NAMESPACE=py-crash-me-dev -p ENVIRONMENT=dev | oc create -f -
oc process -f deployment.yaml -p NAMESPACE=python-crash-me-dev -p IMAGE_NAMESPACE=py-crash-me-dev -p ENVIRONMENT=dev | oc create -f -
#Start the build
oc start-build py-crash-me
oc start-build python-crash-me
#Rollout out the deployment
oc rollout latest dc/py-crash-me
oc rollout latest dc/python-crash-me
#To simulate a rollout to QA
oc new-project py-crash-me-qa
oc new-project python-crash-me-qa
#Create the QA deployment resources
oc process -f deployment.yaml -p NAMESPACE=py-crash-me-qa -p IMAGE_NAMESPACE=py-crash-me-dev -p ENVIRONMENT=qa | oc create -f -
oc process -f deployment.yaml -p NAMESPACE=python-crash-me-qa -p IMAGE_NAMESPACE=py-crash-me-dev -p ENVIRONMENT=qa | oc create -f -
#Tag the images from DEV to QA
oc tag py-crash-me-dev/py-crash-me:latest py-crash-me-qa/py-crash-me:latest
oc tag python-crash-me-dev/py-crash-me:latest py-crash-me-qa/py-crash-me:latest
#Rollout to QA
oc rollout latest dc/py-crash-me
oc rollout latest dc/python-crash-me
```

### The Helm Way
```
#Create the DEV project
oc new-project python-crash-me-dev
#To deploy the build and deployment components
helm install python-crash-me .helm/python-crash-me/ --namespace python-crash-me-dev --values .helm/python-crash-me/values.yaml
#Start the build
oc start-build python-crash-me
#Rollout out the deployment
oc rollout latest dc/python-crash-me
#To simulate a rollout to QA
oc new-project python-crash-me-qa
#Create the QA deployment resources
helm install python-crash-me .helm/python-crash-me/ --namespace python-crash-me-qa --values .helm/python-crash-me/values-qa.yaml
#Tag the images from DEV to QA
oc tag py-crash-me-dev/py-crash-me:latest py-crash-me-qa/py-crash-me:latest
#Rollout to QA
oc rollout latest dc/python-crash-me
```

0 comments on commit 4832f40

Please sign in to comment.