All pods and databases are running successfully
I have a login page, with endpoint /login on the frontend service, but it cannot redirect to the rest-service, can everyone help me to fix the problem (I run it successfully on my local machine manually).
- This is how I built and deploy my front-end service:
nginx.conf:
worker_processes auto;
events {
worker_connections 8000;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $upstream_addr '
'"$http_referer" "$http_user_agent"';
server {
listen 3000;
access_log /var/log/nginx/access.log compression;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
# Proxy API requests to backend
location /api {
proxy_pass $REACT_APP_BACKEND_HOST;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Media: images, icons, video, audio, HTC
location ~* .(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# Javascript and CSS files
location ~* .(?:css|js)$ {
try_files $uri =404;
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# Any route containing a file extension (e.g. /devicesfile.js)
location ~ ^.+..+$ {
try_files $uri =404;
}
}
}
Dockerfile:
FROM node:18-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
entrypoint.sh:
envsubst '$REACT_APP_BACKEND_HOST' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
nginx -g 'daemon off;'
- And here is my config on Kubernetes:
rest-client-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-frontend
labels:
app: client-frontend
spec:
replicas: 1
selector:
matchLabels:
app: client-frontend
template:
metadata:
labels:
app: client-frontend
spec:
containers:
- name: client
image: daniel135dang/client:1.0.0-6
ports:
- containerPort: 3000
envFrom:
- configMapRef:
name: app-config
env:
- name: REACT_APP_BACKEND_HOST
valueFrom:
configMapKeyRef:
name: app-config
key: REACT_APP_BACKEND_HOST
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rest-backend
labels:
app: rest-backend
spec:
replicas: 1
selector:
matchLabels:
app: rest-backend
template:
metadata:
labels:
app: rest-backend
spec:
volumes:
- name: rest-file
persistentVolumeClaim:
claimName: rest-file-pvc
- name: google-credentials
secret:
secretName: google-credentials
containers:
- name: rest-backend
image: daniel135dang/rest:1.0.0-6
ports:
- containerPort: 5000
volumeMounts:
- name: rest-file
mountPath: /mnt/rest/files
- name: google-credentials
mountPath: /app/google_credentials.json
subPath: google_credentials.json
readOnly: true
env:
- name: PORT
value: "5000"
- name: APP_NAME
value: "rest"
- name: HOST
value: "rest-service"
- name: RABBITMQ_HOST
value: "amqp://rabbitmq:5672"
- name: RABBITMQ_FILE_LOCATION_EXCHANGE
value: "uploaded_file_location"
- name: RABBITMQ_OUTPUT_LOCATION_EXCHANGE
value: "output_location"
- name: POSTGRES_HOST
valueFrom:
configMapKeyRef:
name: services-config
key: POSTGRES_HOST
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: services-config
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
configMapKeyRef:
name: services-config
key: POSTGRES_PASSWORD
- name: POSTGRES_DB
valueFrom:
configMapKeyRef:
name: services-config
key: POSTGRES_DB
- name: ROOT_DIR
valueFrom:
configMapKeyRef:
name: services-config
key: ROOT_DIR
- name: REACT_APP_SERVICE_LIST
valueFrom:
configMapKeyRef:
name: app-config
key: REACT_APP_SERVICE_LIST
- name: GUIDELINES_LIST
value: "chapter_title,format_check,page_count"
- name: GOOGLE_CLOUD_STORAGE_BUCKET
valueFrom:
configMapKeyRef:
name: services-config
key: GOOGLE_CLOUD_STORAGE_BUCKET
---
apiVersion: v1
kind: Service
metadata:
name: client-frontend-service
spec:
type: LoadBalancer
selector:
app: client-frontend
ports:
- protocol: TCP
port: 3000
targetPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: rest-service
spec:
type: ClusterIP
selector:
app: rest-backend
ports:
- protocol: TCP
port: 5000
targetPort: 5000
app-config.yml:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
REACT_APP_SERVICE_LIST: "word_frequency,chapter_title,format_check,chapter_summarization,page_count,table_of_content,citation,table_figure_detection"
REACT_APP_BACKEND_HOST: "http://rest-service:5000"