Skip to content

Commit

Permalink
Add kubernetes deployment yaml as option (#30)
Browse files Browse the repository at this point in the history
* first try at deployment yaml

* added service

* working k3s config

* brief addition to readme

* removed comments

* backend now works in kubernetes, and usb should as well

* moved service to top

* ingress comment

---------

Co-authored-by: Max McKelvey <maxmckelvey@Maxs-MBP.positronix.local>
  • Loading branch information
max-at-groundlight and Max McKelvey committed Sep 11, 2023
1 parent 0a3f8bf commit f08f140
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 15 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ Before creating the component, run `sudo usermod -aG docker ggc_user` on your Gr

### Running with Kubernetes

_coming soon_

We recommend a minimal Kubernetes install like [k3s](https://k3s.io/).

> Use the file [`kubernetes.yaml`](./deploy/kubernetes.yaml) file.
1. Create a Kubernetes cluster and install `kubectl` on your machine.
2. Run `kubectl apply -f kubernetes.yaml` in the same directory as the `kubernetes.yaml` file.

## Building from Source

1. Install [Node.js](https://nodejs.org/en/download/) and [Python 3.8+](https://www.python.org/downloads/).
Expand Down
71 changes: 71 additions & 0 deletions deploy/kubernetes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: v1
kind: Service
metadata:
name: monitoring-notification-service
spec:
selector:
app: monitoring-notification-deployment
ports:
- port: 80
targetPort: 3000
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: monitoring-notification-deployment
labels:
app: monitoring-notification-deployment
spec:
replicas: 1
selector:
matchLabels:
app: monitoring-notification-deployment
template:
metadata:
labels:
app: monitoring-notification-deployment
spec:
containers:
- name: monitoring-notification-server-backend
image: docker.io/groundlight/monitoring-notification-server-backend:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8000
securityContext:
privileged: true
volumeMounts:
- name: usb
mountPath: /dev/bus/usb
- name: monitoring-notification-server-frontend
image: docker.io/groundlight/monitoring-notification-server-frontend:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
env:
- name: BACKEND_BASE_URL
value: "http://0.0.0.0:8000"
volumes:
- name: usb
hostPath:
path: /dev/bus/usb
---
# Ingress to make the service accessible from outside the cluster
# This is necessary if you want to access the application's web interface
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: monitoring-notification-service
annotations:
ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: monitoring-notification-service
port:
number: 80
24 changes: 24 additions & 0 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

// This function can be marked `async` if using `await` inside
export function middleware(request: NextRequest) {
console.log("middleware!");
console.log("Request url: " + request.url);

let baseUrl = "http://localhost:8000";
if (process.env.NODE_ENV === "production") {
baseUrl = "http://172.17.0.1:8000";
}
if (global.process.env.BACKEND_BASE_URL) {
baseUrl = global.process.env.BACKEND_BASE_URL;
}
const redirectUrl = new URL(request.nextUrl.pathname, baseUrl);
console.log("Rewritten to: " + redirectUrl.toJSON() + "\n");
return NextResponse.rewrite(redirectUrl);
}

// See "Matching Paths" below to learn more
export const config = {
matcher: "/api/:path*",
};
13 changes: 0 additions & 13 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
rewrites: async () => {
return [
{
source: "/api/:path*",
destination:
process.env.NODE_ENV === "development"
// ? "http://127.0.0.1:8000/api/:path*"
? "http://0.0.0.0:8000/api/:path*"
: ("http://172.17.0.1:8000/api/:path*"),
// : "/api/",
},
];
},
output: 'standalone'
};

Expand Down

0 comments on commit f08f140

Please sign in to comment.