Skip to content
Snippets Groups Projects
Commit 92a9d51e authored by Jesus Galaz's avatar Jesus Galaz
Browse files

feat(kubernetes): complete Kubernetes setup for todo-app with Minikube

- Added Kubernetes deployment specs for `todo-app` and `mongodb`
- Configured NodePort service for external access
- Verified application functionality using `minikube service`
- Enabled persistent storage for MongoDB using PersistentVolumeClaim
- Removed unused `ingress.yml` file
- Provided compatibility for ARM64 and Linux environments
parent cd71134b
No related branches found
No related tags found
1 merge request!15Resolve "Run the application on Kubernetes locally using “minikube”"
Pipeline #17480 passed
services:
mongodb:
image: mongo:latest
container_name: mongodb
ports:
- "27017:27017"
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
- MONGO_INITDB_DATABASE=todo-app
todo-app-1:
build:
context: .
dockerfile: Dockerfile
container_name: todo-app-1
ports:
- "3001:3000"
depends_on:
- mongodb
environment:
- MONGO_URI=${MONGO_URI}
- PORT=3000
todo-app-2:
build:
context: .
dockerfile: Dockerfile
container_name: todo-app-2
ports:
- "3002:3000"
depends_on:
- mongodb
environment:
- MONGO_URI=${MONGO_URI}
nginx:
image: nginx:latest
container_name: nginx
ports:
- "80:80"
depends_on:
- todo-app-1
- todo-app-2
volumes:
- "./nginx.conf:/etc/nginx/nginx.conf:ro"
- "/var/log/nginx/access.log:/var/log/nginx/access.log"
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo:latest
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: mongoAdmin
- name: MONGO_INITDB_ROOT_PASSWORD
value: someRandomPassword123$
volumeMounts:
- name: mongo-data
mountPath: /data/db
volumes:
- name: mongo-data
persistentVolumeClaim:
claimName: mongo-pvc
apiVersion: v1
kind: Service
metadata:
name: mongodb
spec:
ports:
- port: 27017
targetPort: 27017
selector:
app: mongodb
events {
# Set the maximum number of simultaneous connections that can be opened by a worker process
worker_connections 1024;
}
http {
# Define an upstream group for load balancing the todo-app services
upstream todo-app {
ip_hash;
server todo-app-1:3000; # First server in the upstream group
server todo-app-2:3000; # Second server in the upstream group
}
# Define a custom log format for capturing upstream request details
log_format upstreamlog '[$time_local] $remote_addr - $remote_user - $request '
'"$status" $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio" '
'${host} $request_uri '
'$upstream_addr ';
server {
listen 80; # Listen on port 80 for incoming HTTP requests
location / {
# Proxy requests to the upstream todo-app group
proxy_pass http://todo-app;
proxy_http_version 1.1; # Use HTTP/1.1 for proxying
proxy_set_header Upgrade $http_upgrade; # Set the Upgrade header
proxy_set_header Connection 'upgrade'; # Set the Connection header to upgrade
proxy_set_header Host $host; # Forward the original Host header
proxy_cache_bypass $http_upgrade; # Bypass cache for upgraded requests
# Log access requests using the defined upstream log format
access_log /var/log/nginx/access.log upstreamlog;
}
}
}
apiVersion: apps/v1
kind: Deployment
metadata:
name: todo-app
labels:
app: todo-app
spec:
replicas: 2
selector:
matchLabels:
app: todo-app
template:
metadata:
labels:
app: todo-app
spec:
containers:
- name: todo-app
image: todo-app:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
env:
- name: MONGO_URI
value: mongodb://mongoAdmin:someRandomPassword123$@mongodb:27017/todo-app?authSource=admin
apiVersion: v1
kind: Service
metadata:
name: todo-app
spec:
ports:
- port: 3000
targetPort: 3000
selector:
app: todo-app
type: NodePort
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment