Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,6 @@ __marimo__/

# Terraform
.terraform/

# helm, local dev
values.local.yaml
59 changes: 42 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,41 @@ GitHub Push → GitHub Actions → Build & Test → Push to ECR → Deploy to EK
- Docker **v29.3.0** (both client and server)
- Docker-compose **v5.1.0**
- Kubernetes (kubectl **v1.35.1**, Kustomize **v5.7.1**)
- Helm **v3.19.0**
- minikube **v1.38.1** (for local dev/test)
- Act **v0.2.82** (for local ci/cd pipeline testing)
- AWS Services: VPC/ ECR/ EKS /EC2 /IAM

## Project Tree
```bash.
simple-app
├── .github
│   └── workflows
├── .github
│   └── workflows # ci/cd workflow files
│   ├── cd.yaml
│   └── ci.yaml
├── app
├── app # simple python fastApi app
│   ├── main.py
│   ├── requirements.txt
│   └── tests
│   ├── __init__.py
│   ├── main_test.py
├── docker-compose.dev.yaml
├── docker-compose.yaml
├── docker-compose.dev.yaml # docker compose for local dev
├── docker-compose.yaml # docker compose for prod
├── Dockerfile
├── .gitignore
├── k8s
│   ├── deployment.yaml
│   ├── ingress.yaml
│   ├── resourceQuota.yaml
│   └── service.yaml
├── values.local.yaml # ignored file in the tree unless created locally
├── README.md
└── terraform
├── simple-app # Helm Chart
│   ├── charts
│   ├── Chart.yaml
│   ├── templates
│   │   ├── deployment.yaml
│   │   ├── _helpers.tpl
│   │   ├── ingress.yaml
│   │   ├── resourceQuota.yaml
│   │   └── service.yaml
│   └── values.yaml
└── terraform # Iac with terraform
├── helm.tf
├── main.tf
├── outputs.tf
Expand All @@ -63,7 +70,7 @@ export AWS_SECRET_ACCESS_KEY="<your-iam-secret-access-key>"
# - `AmazonEC2ContainerRegistryFullAccess`
# - `AmazonEKSWorkerNodePolicy`

# setup minkube cluster with custom cpu/ram
# setup minikube cluster with custom cpu/ram
minikube start --cpus 4 --memory 4096
eval $(minikube docker-env)

Expand All @@ -72,20 +79,34 @@ eval $(minikube docker-env)
# - docker cannot authenticate you, then just use `docker logout`, `docker login` to reauthenticate

# building docker image
# Note: if the image name is changed in the future in the deployment\'s template section, then you must change it too
# if it is dynamic (with sed, which i plan to do) i\'ll make the necessary changes in this documentation
docker build -t simple-app:test . (for testing)
docker build -t simple-app:test .

# loading image to minikube cluster
minikube image load simple-app:test

# if you clone this repo
# the image is sat to "IMAGE_PLACEHOLDER", so you need to run this in order to run test locally
# so we'll create a local file override file ignoredby git (via .gitignore)
# Note: make sure that you run the following command in the root directory
cat > values.local.yaml <<EOF
image:
repository: simple-app
tag: test
EOF

# add the ignored file in the ".gitignore" file
grep -rye "Values.local.yaml" .gitignore || echo "# helm, local dev \nvalues.local.yaml" >> .gitignore

# create a namespace
kubectl get ns simple-app-ns || kubectl create ns simple-app-ns

# apply changes to manifests with kubectl
kubectl apply -f k8s/
# install the helm chart
helm install simple-app ./simple-app -n simple-app-ns -f values.local.yaml

# Watch for errors via **describe/get/logs** subcommands
kubectl get pods -n simple-app-ns
kubectl describe pod <target-pod-name> -n simple-app-ns
kubectl logs <target-pod-name> -n simple-app-ns

# if no errors found, then use your webclient or browser (because it\'s a fastApi app) to test it

Expand All @@ -107,5 +128,9 @@ kubectl port-forward -n simple-app-ns svc/simple-app-service 8080:80
# use "localhost:8080" to access the endpoints
# try the "/" and "/health" endpoints
# if you get messages in json format then you're good to go

# Note: for users that made changed after first install
# to apply changes after first install (instead of helm install)
helm upgrade simple-app ./simple-app -n simple-app-ns -f values.local.yaml
```

41 changes: 0 additions & 41 deletions k8s/deployment.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions k8s/ingress.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions k8s/resourceQuota.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions k8s/service.yaml

This file was deleted.

23 changes: 23 additions & 0 deletions simple-app/.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/
24 changes: 24 additions & 0 deletions simple-app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: simple-app
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: 0.1.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.16.0"
61 changes: 61 additions & 0 deletions simple-app/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "simple-app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "simple-app.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "simple-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "simple-app.labels" -}}
helm.sh/chart: {{ include "simple-app.chart" . }}
{{ include "simple-app.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "simple-app.selectorLabels" -}}
app: {{ include "simple-app.name" . }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "simple-app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "simple-app.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
42 changes: 42 additions & 0 deletions simple-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "simple-app.fullname" . }}
namespace: {{ .Values.namespace.global }}
labels:
{{- include "simple-app.selectorLabels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "simple-app.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "simple-app.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: simple-app
imagePullPolicy: {{ .Values.container.image.policies.imagePullPolicy }}
{{/* image: simple-app:test */}}
image: IMAGE_PLACEHOLDER
ports:
- containerPort: {{ .Values.container.containerPort }}
resources:
requests:
cpu: "200m"
memory: "16Mi"
limits:
cpu: "300m"
memory: "32Mi"
readinessProbe:
httpGet:
path: {{ .Values.readinessProbe.httpGet.path }}
port: {{ .Values.readinessProbe.httpGet.port }}
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
livenessProbe:
httpGet:
path: {{ .Values.livenessProbe.httpGet.path }}
port: {{ .Values.livenessProbe.httpGet.port }}
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
17 changes: 17 additions & 0 deletions simple-app/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: simple-app-ingress
namespace: {{ .Values.namespace.global }}
spec:
ingressClassName: {{ .Values.ingress.className.name }}
rules:
- http:
paths:
- path: {{ .Values.ingress.className.rules.paths.root.path }}
pathType: {{ .Values.ingress.className.rules.paths.root.pathType }}
backend:
service:
name: {{ .Values.ingress.className.rules.paths.root.backend.service.name }}
port:
number: {{ .Values.ingress.className.rules.paths.root.backend.service.port }}
10 changes: 10 additions & 0 deletions simple-app/templates/resourceQuota.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ResourceQuota
metadata:
name: pods-medium
namespace: {{ .Values.namespace.global }}
spec:
hard:
pods: {{ .Values.namespace.reqourceQuota.hard.pods }}
memory: {{ .Values.namespace.reqourceQuota.hard.memory }}
cpu: {{ .Values.namespace.reqourceQuota.hard.cpu }}
Loading
Loading