Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip/sal/helm #17

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/build-push-helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: build and push helm
on:
push:
branches:
- main
- wip/sal/helm
permissions:
contents: read
packages: write
jobs:
helm-build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: helm build
uses: azure/setup-helm@v1
with:
version: v3.12.0
- name: helm login
run: helm registry login -u ${{ github.actor }} -p ${{ github.token}} ghcr.io
- name: helm build and release
run: ci/make_helm_release.sh
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ For kind this will unintuitively be the `INTERNAL-IP`, for a cloud cluster use t

E.g. in a browser go to: `172.19.0.2:<nodePort>`

### Kubernetes using Helm

Helm chart is supplied in the `helm/quotes-flask` directory.

Deploying the application using `helm`:

```sh
helm install quotes-flask helm/quotes-flask
```

See the release with `helm list`, and get the NodePort with `kubectl get service frontend`.

You can change the values of the helm chart by supplying a `values.yaml` file, or by using the `--set` flag.

```sh
helm install quotes-flask helm/quotes-flask --set frontend.tag="3.0.0"
```

## Developing

### docker-compose
Expand Down
30 changes: 30 additions & 0 deletions ci/make_helm_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

REGISTRY="ghcr.io/eficode-academy"
FRONTEND_REPOSITORY="quotes-flask-frontend"
BACKEND_REPOSITORY="quotes-flask-backend"
HELM_REPOSITORY="quotes-flask-helm"
QUOTES="quotes-flask"
VERSIONS="
1.0.0
2.0.0
3.0.0
4.0.0
5.0.0
"

echo "Creating Helm releases ..."
cd helm

for VERSION in $VERSIONS; do
echo "Creating Helm release: $VERSION"
echo "generating helm release for $VERSION"
VERSION=$VERSION yq -i '.version = env(VERSION)' quotes-flask/Chart.yaml
VERSION=$VERSION yq -i '.appVersion = env(VERSION)' quotes-flask/Chart.yaml
VERSION=$VERSION yq -i '.backend.tag = env(VERSION)' quotes-flask/values.yaml
VERSION=$VERSION yq -i '.frontend.tag = env(VERSION)' quotes-flask/values.yaml
echo "helm push quotes-flask $VERSION"
helm package quotes-flask
helm push $QUOTES-$VERSION.tgz oci://ghcr.io/eficode-academy

done
23 changes: 23 additions & 0 deletions helm/quotes-flask/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
21 changes: 21 additions & 0 deletions helm/quotes-flask/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: quotes-flask
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: "1.0.0"
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.0.0"
1 change: 1 addition & 0 deletions helm/quotes-flask/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Congratulations you have now installed the quotes-flask application on your machine!
9 changes: 9 additions & 0 deletions helm/quotes-flask/templates/backend-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: backend-config
data:
# all data points are handled as strings
backend_host: "backend"
backend_port: "5000"
31 changes: 31 additions & 0 deletions helm/quotes-flask/templates/backend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: backend
name: backend
spec:
replicas: {{ .Values.backend.replicas }}
selector:
matchLabels:
app: backend
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: backend
spec:
containers:
- image: ghcr.io/eficode-academy/quotes-flask-backend:{{ .Values.backend.tag }}
name: quotes-flask-backend
ports:
- containerPort: 5000
resources: {}
envFrom:
- configMapRef:
name: postgres-config
- secretRef:
name: postgres-secret
status: {}
17 changes: 17 additions & 0 deletions helm/quotes-flask/templates/backend-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: backend
name: backend
spec:
ports:
- port: 5000
protocol: TCP
targetPort: 5000
selector:
app: backend
type: ClusterIP
status:
loadBalancer: {}
44 changes: 44 additions & 0 deletions helm/quotes-flask/templates/frontend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: frontend
name: frontend
spec:
replicas: {{ .Values.frontend.replicas }}
selector:
matchLabels:
app: frontend
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: frontend
spec:
containers:
- image: ghcr.io/eficode-academy/quotes-flask-frontend:{{ .Values.frontend.tag }}
name: quotes-flask-frontend
ports:
- containerPort: 5000
resources: {}
env:
# load namespace from downward api
# https://github.com/kubernetes/kubernetes/blob/release-1.0/docs/user-guide/downward-api.md
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BACKEND_HOST
valueFrom:
configMapKeyRef:
name: backend-config
key: backend_host
- name: BACKEND_PORT
valueFrom:
configMapKeyRef:
name: backend-config
key: backend_port

status: {}
16 changes: 16 additions & 0 deletions helm/quotes-flask/templates/frontend-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: frontend
name: frontend
spec:
ports:
- port: 5000
protocol: TCP
targetPort: 5000
selector:
app: frontend
type: {{ .Values.frontend.service.type}}
status:
9 changes: 9 additions & 0 deletions helm/quotes-flask/templates/postgres-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
data:
DB_HOST: postgres
DB_PORT: '5432'
DB_USER: superuser
DB_NAME: quotes
50 changes: 50 additions & 0 deletions helm/quotes-flask/templates/postgres-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: postgres
name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: postgres
spec:
volumes:
- name: postgres-pvc # name we can reference below in container
persistentVolumeClaim:
claimName: postgres-pvc # name of the actual pvc
containers:
- image: postgres:14.3
name: postgres
ports:
- containerPort: 5432
resources: {}
env:
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: postgres-config
key: DB_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: DB_PASSWORD
- name: POSTGRES_DB
valueFrom:
configMapKeyRef:
name: postgres-config
key: DB_NAME
volumeMounts:
- name: postgres-pvc
mountPath: /var/lib/postgresql/data
subPath: postgres
status: {}
12 changes: 12 additions & 0 deletions helm/quotes-flask/templates/postgres-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
spec:
# default. Use `kubectl get sc` too what storage classes are configured
storageClassName: "gp2"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
7 changes: 7 additions & 0 deletions helm/quotes-flask/templates/postgres-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
data:
DB_PASSWORD: Y29tcGxpY2F0ZWQ=
kind: Secret
metadata:
creationTimestamp:
name: postgres-secret
17 changes: 17 additions & 0 deletions helm/quotes-flask/templates/postgres-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: postgres
name: postgres
spec:
ports:
- port: 5432
protocol: TCP
targetPort: 5432
selector:
app: postgres
type: ClusterIP
status:
loadBalancer: {}
8 changes: 8 additions & 0 deletions helm/quotes-flask/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
backend:
replicas: 1
tag: release
frontend:
replicas: 1
service:
type: NodePort
tag: release
Loading