Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
feature: adding kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
lzfrs committed Jul 7, 2024
1 parent 7c14309 commit 8b7344d
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ override.tf.json

# Ignore CLI configuration files
.terraformrc
terraform.rc
terraform.rc

data/*
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
dev:
air
air

install:
go mod tidy
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ The documentation can be founded at the path `/docs/swagger.yaml` or accessing t

## Infrastructure

[Requirements Infrastructure](https://github.com/pangolin-do-golang/tech-challenge/blob/main/terraform/README.md)

[Requierments Infrastructure](https://github.com/pangolin-do-golang/tech-challenge/blob/main/terraform/README.md)
## Kubernetes

The Kubernetes templates are located at the `/deploy/k8s` folder, you can use it to create a local k8s setup with minikube

The order of execution is:
1. namespaces
2. secret > you should update the secret value with the database password
3. deployment
4. hpa
5. secret


You can forward the port with the following command:

```bash
kubectl port-forward svc/tech-challenge-service 4000:80 -n dev
```
67 changes: 67 additions & 0 deletions deploy/k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: tech-challenge-deployment
labels:
app: tech-challenge
spec:
replicas: 2
selector:
matchLabels:
app: tech-challenge
template:
metadata:
labels:
app: tech-challenge
spec:
containers:
- name: tech-challenge-container
image: ghcr.io/pangolin-do-golang/tech-challenge:7c14309
ports:
- containerPort: 8080

env:
- name: DB_USERNAME
value: postgres.jhwmlvbsmtyluoccjabw

- name: DB_HOST
value: aws-0-sa-east-1.pooler.supabase.com

- name: DB_NAME
value: postgres

- name: DB_PORT
value: "6543"

- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-password-secret
key: db-password

livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
successThreshold: 1

readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3
successThreshold: 1
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "512Mi"
18 changes: 18 additions & 0 deletions deploy/k8s/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: tech-challenge-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: tech-challenge-deployment
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
11 changes: 11 additions & 0 deletions deploy/k8s/namespaces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Namespace
metadata:
name: dev

---

apiVersion: v1
kind: Namespace
metadata:
name: prd
7 changes: 7 additions & 0 deletions deploy/k8s/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: db-password-secret
type: Opaque
data:
db-password: bXlzZWN1cmVwYXNzd29yZA==
11 changes: 11 additions & 0 deletions deploy/k8s/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: tech-challenge-service
spec:
selector:
app: tech-challenge
ports:
- protocol: TCP
port: 80
targetPort: 8080

0 comments on commit 8b7344d

Please sign in to comment.