-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from bespinian/k8s
Add plain k8s setup
- Loading branch information
Showing
11 changed files
with
465 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Kubernetes Deployment | ||
|
||
This folder contains plain YML files for a Kubernetes setup of our todo app. It is basically the | ||
same architecture as the [Docker Compose setup](../). | ||
|
||
You can install this in a local Kubernetes cluster using Docker Desktop. In this case you also need | ||
to install Traefik as Ingress controller. If you install this in some other cluster, you might | ||
already have an ingress controller and don't need Traefik. That's up to you. | ||
|
||
## Prerequisites | ||
|
||
You need a Kubernetes cluster of some sort. If you don't have one at hand, just activate the one | ||
in Docker Desktop. The internet tells you how. | ||
|
||
If you have no ingress controller in your cluster, install Traefik as follows: | ||
|
||
```sh | ||
kubectl create ns traefik | ||
kubectl -n traefik apply -f k8s/traefik | ||
``` | ||
|
||
## Install ICT | ||
|
||
The provided YAML files assume you have a local cluster and therefore access to it via localhost. | ||
If you're working with a "real" remote cluster, you might need to change the | ||
[Ingress Resource](./apps/ingress.yaml). | ||
|
||
```sh | ||
kubectl create namespace todo | ||
kubectl --namespace todo apply -f k8s/services | ||
kubectl --namespace todo apply -f k8s/apps | ||
``` | ||
|
||
In a remote cluster, you should be done and be able to open the app in your browser. | ||
|
||
In a local cluster, we now need to open a port-forward to Traefik. Then we can access the app on | ||
localhost as usual. | ||
|
||
```sh | ||
kubectl --namespace traefik port-forward services/traefik-web 8000:80 | ||
open localhost:8000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: frontend | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: frontend | ||
template: | ||
metadata: | ||
labels: | ||
app: frontend | ||
spec: | ||
containers: | ||
- name: frontend | ||
image: ghcr.io/bespinian/insanely-complex-todo/frontend:latest | ||
readinessProbe: | ||
initialDelaySeconds: 1 | ||
periodSeconds: 10 | ||
httpGet: | ||
port: 80 | ||
path: / | ||
livenessProbe: | ||
initialDelaySeconds: 1 | ||
periodSeconds: 10 | ||
httpGet: | ||
port: 80 | ||
path: / | ||
resources: | ||
requests: | ||
memory: "50Mi" | ||
cpu: "50m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
ports: | ||
- containerPort: 80 | ||
name: web | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: frontend | ||
spec: | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
targetPort: web | ||
name: web | ||
selector: | ||
app: frontend | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: frontend | ||
spec: | ||
rules: | ||
- http: | ||
paths: | ||
- path: / | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: frontend | ||
port: | ||
number: 80 | ||
- path: /api/tasks | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: tasks | ||
port: | ||
number: 80 | ||
- path: /ws | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: websocket-server | ||
port: | ||
number: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: tasks | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: tasks | ||
template: | ||
metadata: | ||
labels: | ||
app: tasks | ||
spec: | ||
containers: | ||
- name: tasks | ||
image: ghcr.io/bespinian/insanely-complex-todo/tasks:latest | ||
env: | ||
- name: MONGODB_URI | ||
value: mongodb://mongo | ||
- name: REDIS_URL | ||
value: redis://redis/0 | ||
readinessProbe: | ||
initialDelaySeconds: 1 | ||
periodSeconds: 10 | ||
httpGet: | ||
port: 3000 | ||
path: livez | ||
livenessProbe: | ||
initialDelaySeconds: 1 | ||
periodSeconds: 10 | ||
httpGet: | ||
port: 3000 | ||
path: readyz | ||
resources: | ||
requests: | ||
memory: "50Mi" | ||
cpu: "50m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: tasks | ||
spec: | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
targetPort: 3000 | ||
selector: | ||
app: tasks | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: websocket-server | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: websocket-server | ||
template: | ||
metadata: | ||
labels: | ||
app: websocket-server | ||
spec: | ||
containers: | ||
- name: websocket-server | ||
image: ghcr.io/bespinian/insanely-complex-todo/websocket-server:latest | ||
env: | ||
- name: REDIS_URL | ||
value: redis://redis/0 | ||
- name: WEBSOCKET_SERVER_HOST | ||
value: "0.0.0.0" | ||
- name: WEBSOCKET_SERVER_PORT | ||
value: "8765" | ||
resources: | ||
requests: | ||
memory: "128Mi" | ||
cpu: "100m" | ||
limits: | ||
memory: "512Mi" | ||
cpu: "500m" | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: websocket-server | ||
spec: | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
targetPort: 8765 | ||
selector: | ||
app: websocket-server | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: mongo | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: mongo | ||
template: | ||
metadata: | ||
labels: | ||
app: mongo | ||
spec: | ||
containers: | ||
- name: mongo | ||
image: mongo:8.0 | ||
resources: | ||
requests: | ||
memory: "100Mi" | ||
cpu: "100m" | ||
limits: | ||
memory: "256Mi" | ||
cpu: "500m" | ||
ports: | ||
- containerPort: 27017 | ||
volumeMounts: | ||
- name: mongo-data | ||
mountPath: /data/db | ||
volumes: | ||
- name: mongo-data | ||
persistentVolumeClaim: | ||
claimName: mongo-data | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: mongo | ||
spec: | ||
ports: | ||
- port: 27017 | ||
protocol: TCP | ||
targetPort: 27017 | ||
selector: | ||
app: mongo | ||
type: ClusterIP | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: mongo-data | ||
spec: | ||
resources: | ||
requests: | ||
storage: 50M | ||
volumeMode: Filesystem | ||
accessModes: | ||
- ReadWriteOnce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: redis | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: redis | ||
template: | ||
metadata: | ||
labels: | ||
app: redis | ||
spec: | ||
containers: | ||
- name: redis | ||
image: redis:7-alpine | ||
resources: | ||
requests: | ||
memory: "50Mi" | ||
cpu: "100m" | ||
limits: | ||
memory: "256Mi" | ||
cpu: "500m" | ||
readinessProbe: | ||
exec: | ||
command: ["redis-cli", "--raw", "incr", "ping"] | ||
ports: | ||
- containerPort: 6379 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: redis | ||
spec: | ||
ports: | ||
- port: 6379 | ||
protocol: TCP | ||
targetPort: 6379 | ||
selector: | ||
app: redis | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: traefik | ||
namespace: traefik | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: traefik | ||
template: | ||
metadata: | ||
labels: | ||
app: traefik | ||
spec: | ||
serviceAccountName: traefik-account | ||
containers: | ||
- name: traefik | ||
image: traefik:v3.1 | ||
args: | ||
- "--log.level=info" | ||
- "--api.insecure=true" | ||
- "--entryPoints.web.address=:80" | ||
- "--providers.kubernetesingress" | ||
- "--ping.entrypoint=traefik" | ||
resources: | ||
requests: | ||
memory: "50Mi" | ||
cpu: "100m" | ||
limits: | ||
memory: "128Mi" | ||
cpu: "500m" | ||
ports: | ||
- containerPort: 80 | ||
name: web | ||
- containerPort: 8080 | ||
name: dashboard |
Oops, something went wrong.