Skip to content

Commit

Permalink
Deploying next.js in kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
jurabek committed Feb 6, 2024
1 parent 009fd0a commit 9d7adc2
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 98 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ The architecture proposes a micro-service oriented architecture implementation w
| 1. | Identity API (.NET Core + IdentityServer4) | Identity management service, powered by OAuth2 and OpenID Connect | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/identity-api.yml/badge.svg) | [dev](#) \| [prod](#) |
| 2. | Cart API (Golang + Redis) | Manages customer basket in order to keep items on in-memory cache using redis | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/cart-api.yml/badge.svg) | [dev](#) \| [prod](#) |
| 3. | Catalog API (Rust + Rocket, PostgreSQL) | Manages data for showing restaurant menu | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/catalog-api.yml/badge.svg) | [dev](#) \| [prod](#) |
| 4. | Order API (Java + Spring Boot) | Manages customer orders | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/order-api.yml/badge.svg) | [dev](#) \| [prod](#) |
| 4. | Order API (Java + Quarkus + Native Build) | Manages customer orders | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/order-api.yml/badge.svg) | [dev](#) \| [prod](#) |
| 5. | Ceckout API (Node.js + Express) | Responsible for checkout functionality | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/checkout-api.yml/badge.svg) | [dev](#) \| [prod](#) |
| 6. | Payment API (Golang) | Fake payment API (Payment service abstracting PSP) | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/payment-api.yml/badge.svg) | [dev](#) \| [prod](#) |
| 6. | Web App (Typescript + Next.js ❤️ ) | Frontend application | ![Build Status](https://github.com/chayxana/Restaurant-App/actions/workflows/web-app.yml/badge.svg) | [dev](#) \| [prod](#) |

## Web App
Web app developed using Next.js with SSR
Expand Down
6 changes: 3 additions & 3 deletions k8s-kustomize/services/identity-api/base/.env.secret
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
db.username=default-db-user
db.password=strong-db-password
db.name=restaurant_identity_database
DB_NAME=restaurant_identity_database
DB_USER=default-db-user
DB_PASSWORD=strong-db-password
15 changes: 8 additions & 7 deletions k8s-kustomize/services/identity-api/base/config.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
db.host=identity-pgsql-database
base.path=/identity
basket.url=
menu.url=
order.url=
dashboard.url=
env=Development
ASPNETCORE_ENVIRONMENT=Development
DB_HOST=identity-pgsql-database
PATH_BASE=/identity
MENU_API_URL=http://localhost:8080/menu
ORDER_API_URL=http://localhost:8080/order
BASKET_API_URL=http://localhost:8080/basket
DASHBOARD_APP_URL=http://localhost:8080/dashboard
IDENTITY_URL_PUB=http://localhost:8080/identity
94 changes: 23 additions & 71 deletions k8s-kustomize/services/identity-api/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,77 +17,29 @@ spec:
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
image: jurabek/identity
env:
- name: OrchestrationType
value: k8s
- name: ASPNETCORE_ENVIRONMENT
valueFrom:
configMapKeyRef:
name: identity-api
key: env
- name: PATH_BASE
valueFrom:
configMapKeyRef:
name: identity-api
key: base.path
- name: BASKET_API_URL
valueFrom:
configMapKeyRef:
name: identity-api
key: basket.url
- name: MENU_API_URL
valueFrom:
configMapKeyRef:
name: identity-api
key: menu.url
- name: ORDER_API_URL
valueFrom:
configMapKeyRef:
name: identity-api
key: order.url
- name: DASHBOARD_APP_URL
valueFrom:
configMapKeyRef:
name: identity-api
key: dashboard.url
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: identity-api
key: db.host
- name: DB_NAME
valueFrom:
secretKeyRef:
name: identity-api
key: db.name
- name: DB_USER
valueFrom:
secretKeyRef:
name: identity-api
key: db.username
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: identity-api
key: db.password
readinessProbe:
httpGet:
path: /hc
port: 80
initialDelaySeconds: 60
timeoutSeconds: 5
periodSeconds: 30
successThreshold: 1
failureThreshold: 5
livenessProbe:
httpGet:
path: /liveness
port: 80
initialDelaySeconds: 10
periodSeconds: 15
successThreshold: 1
failureThreshold: 5
image: identity-api
envFrom:
- configMapRef:
name: identity-api
- secretRef:
name: identity-api
# readinessProbe:
# httpGet:
# path: /hc
# port: 80
# initialDelaySeconds: 60
# timeoutSeconds: 5
# periodSeconds: 30
# successThreshold: 1
# failureThreshold: 5
# livenessProbe:
# httpGet:
# path: /liveness
# port: 80
# initialDelaySeconds: 10
# periodSeconds: 15
# successThreshold: 1
# failureThreshold: 5
resources:
requests:
memory: "64Mi"
Expand Down
14 changes: 7 additions & 7 deletions k8s-kustomize/services/identity-api/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ kind: Kustomization

namespace: dev

bases:
resources:
- "../base"

patchesStrategicMerge:
- http_route_patch.yaml
# patchesStrategicMerge:
# - http_route_patch.yaml

configMapGenerator:
- name: identity-api
envs: [config.env]
behavior: merge
# configMapGenerator:
# - name: identity-api
# envs: [config.env]
# behavior: merge
2 changes: 1 addition & 1 deletion k8s-kustomize/services/payment-api/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ kind: Kustomization

namespace: dev

bases:
resources:
- ../base
6 changes: 3 additions & 3 deletions k8s-kustomize/services/web-app/base/config.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
API_BASE_URL=http://localost:80
NEXTAUTH_URL=http://localhost:80
AUTH_ISSUER=http://localhost:80/identity
API_BASE_URL=http://gateway-istio.istio-system # internally we call istio gateway by service name
NEXTAUTH_URL=http://localhost:3001
AUTH_ISSUER=http://gateway-istio.istio-system/identity
AUTH_CLIENT_ID=nextjs-web-app
OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector.monitoring:4317
73 changes: 73 additions & 0 deletions k8s-kustomize/services/web-app/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
namespace: default
labels:
app: web-app
spec:
selector:
matchLabels:
app: web-app
replicas: 1
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web-app
image: web-app
resources:
requests:
cpu: 300m
memory: 300Mi
limits:
cpu: 1000m
memory: 1Gi
envFrom:
- configMapRef:
name: web-app
- secretRef:
name: web-app
ports:
- containerPort: 3000
name: web-app
volumeMounts:
- name: localtime
mountPath: /etc/localtime

- name: config
mountPath: /app/.env.local
readOnly: true
subPath: .env.local

- name: secret
mountPath: /app/.env.production
readOnly: true
subPath: .env.production

volumes:
- name: localtime
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai

- name: config
configMap:
name: web-app
items:
- key: config-file
path: .env.local

- name: secret
secret:
secretName: web-app
items:
- key: secret-file
path: .env.production
restartPolicy: Always
11 changes: 7 additions & 4 deletions k8s-kustomize/services/web-app/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- "deployment.yaml"

generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- envs:
- config.env
- files:
- config-file=config.env
name: web-app

secretGenerator:
- envs:
- .secret
- files:
- secret-file=.secret.env
name: web-app

images:
Expand Down
1 change: 0 additions & 1 deletion src/backend/services/web-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ COPY --from=builder /app/.next/static ./.next/static

RUN ls -a


EXPOSE 3000

ENV PORT 3000
Expand Down

0 comments on commit 9d7adc2

Please sign in to comment.