Kubernetes Deployment - WIP

This commit is contained in:
Roger Sacchelli 2024-04-16 22:56:47 -03:00
parent b947d42ac2
commit 61f93f49e5
7 changed files with 101 additions and 40 deletions

View File

@ -2,7 +2,7 @@ FROM golang:1.22@sha256:82e07063a1ac3ee59e6f38b1222e32ce88469e4431ff6496cc40fb9a
WORKDIR /app WORKDIR /app
COPY ../ ./ COPY ../ ./
RUN CGO_ENABLED=0 GOOS=linux go build -o mqtt cmd/mqtt/main.go RUN CGO_ENABLED=0 GOOS=linux go build -o mqtt cmd/mqtt/main.go
CMD pwd
FROM alpine:3.14@sha256:0f2d5c38dd7a4f4f733e688e3a6733cb5ab1ac6e3cb4603a5dd564e5bfb80eed FROM alpine:3.14@sha256:0f2d5c38dd7a4f4f733e688e3a6733cb5ab1ac6e3cb4603a5dd564e5bfb80eed
COPY --from=builder /app/mqtt / COPY --from=builder /app/mqtt /
ENTRYPOINT ["/mqtt"] ENTRYPOINT ["/mqtt"]

View File

@ -2,15 +2,90 @@
## Requirements ## Requirements
Kubernetes 1.28+
### Standalone Installation ### Standalone Installation
Node: Single Node:
* 8 vCPUs * 8 vCPUs
* 8 GB RAM * 8 GB RAM
# Installation # Installation
## Download Files
```shell
git clone https://github.com/OktopUSP/oktopus
export DEPLOYMENT_PATH=oktopus/deploy/kubernetes
```
## MongoBD ## MongoBD
```shell
# Mongo DB Operator at mongodb namespace
helm repo add mongodb https://mongodb.github.io/helm-charts
helm install community-operator mongodb/community-operator --namespace mongodb --create-namespace
# Mongo DB ReplicaSet
export DEPLOYMENT_PATH=oktopus/deploy/kubernetes
kubectl apply -f $DEPLOYMENT_PATH/mongodb.yaml -n mongodb
# Check Installation
kubectl get pods -n mongodb
```
## NATS Server
```shell
# Download the NATS charts
helm repo add nats https://nats-io.github.io/k8s/helm/charts/
# Install NATS with Jetstream Enabled
helm install nats nats/nats --set config.jetstream.enabled=true
```
## Oktopus
<b>Node Ports</b>
For this deployment, we are not using a load balancer and kubernetes is deployed on-premises so we are using Nodeports to insource the client traffic into cluster. below the ports set on deployment files:
1. MQTT broker service (mqtt-svc): 30000
2. Frontend (frontend-svc): 30001
3. SocketIO: (socketio-svc): 30002
4. Controller (controller-svc): 30003
5. WebSocket (ws-svc): 30005
Before deploying the files, edit the frontend.yaml file to set the correct enviroment variables:
```yaml
env:
- name: NEXT_PUBLIC_REST_ENDPOINT
value: "<FRONTEND_IP>:30003"
- name: NEXT_PUBLIC_WS_ENDPOINT
value: "<FRONTEND_IP>:30005"
```
```shell
kubectl apply -f $DEPLOYMENT_PATH/mqtt.yaml
kubectl apply -f $DEPLOYMENT_PATH/mqtt-adapter.yaml
kubectl apply -f $DEPLOYMENT_PATH/adapter.yaml
kubectl apply -f $DEPLOYMENT_PATH/controller.yaml
kubectl apply -f $DEPLOYMENT_PATH/socketio.yaml
kubectl apply -f $DEPLOYMENT_PATH/frontend.yaml
kubectl apply -f $DEPLOYMENT_PATH/ws.yaml
kubectl apply -f $DEPLOYMENT_PATH/ws-adapter.yaml
```
### Checking cluster status:
```shell
kubectl get pods
kubectl get svc
```

View File

@ -1,21 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
labels:
app: backend
spec:
replicas: 1
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: backend:latest
ports:
- containerPort: 8080

View File

@ -8,7 +8,7 @@ spec:
matchLabels: matchLabels:
app: frontend app: frontend
strategy: strategy:
type: Recreate # Specify the Recreate strategy type: Recreate # Specify the Recreate strategy
template: template:
metadata: metadata:
labels: labels:
@ -16,16 +16,22 @@ spec:
spec: spec:
containers: containers:
- name: frontend - name: frontend
image: rogersacchelli/frontend:1.0.3 image: oktopusp/frontend:latest
ports: resources:
requests:
memory: 64Mi
cpu: 100m
limits:
memory: 256Mi
cpu: 200m
ports:
- containerPort: 3000 - containerPort: 3000
imagePullPolicy: Always imagePullPolicy: IfNotPresent
env: env:
- name: NEXT_PUBLIC_REST_ENDPOINT - name: NEXT_PUBLIC_REST_ENDPOINT
value: "192.168.1.130:30003" value: "192.168.1.130:30003"
- name: NEXT_PUBLIC_WS_ENDPOINT - name: NEXT_PUBLIC_WS_ENDPOINT
value: "192.168.1.130:30002" value: "192.168.1.130:30005"
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service

View File

@ -9,7 +9,8 @@ spec:
- protocol: TCP - protocol: TCP
port: 1883 port: 1883
targetPort: 1883 targetPort: 1883
type: ClusterIP nodePort: 30000
type: NodePort
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@ -33,10 +34,10 @@ spec:
resources: resources:
requests: requests:
memory: 64Mi memory: 64Mi
cpu: 0.1 cpu: 100m
limits: limits:
memory: 256Mi memory: 256Mi
cpu: 0.2 cpu: 200m
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
env: env:
- name: MQTT_PORT - name: MQTT_PORT

View File

@ -31,13 +31,13 @@ spec:
image: oktopusp/ws:latest image: oktopusp/ws:latest
ports: ports:
- containerPort: 8080 - containerPort: 8080
#resources: resources:
#requests: requests:
#memory: 64Mi memory: 64Mi
#cpu: 0.1 cpu: 100m
#limits: limits:
#memory: 256Mi memory: 256Mi
#cpu: 0.2 cpu: 200m
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
env: env:
- name: SERVER_PORT - name: SERVER_PORT

View File

@ -6,7 +6,7 @@ COPY ./ ./
RUN npm install RUN npm install
RUN NEXT_PUBLIC_REST_ENPOINT=REST_API_URL NEXT_PUBLIC_WS_ENPOINT=WS_URL npm run build RUN NEXT_PUBLIC_REST_ENDPOINT=REST_API_URL NEXT_PUBLIC_WS_ENDPOINT=WS_URL npm run build
RUN ls -la && echo "Listing directory contents done" RUN ls -la && echo "Listing directory contents done"