admin pannel k8s

This commit is contained in:
tusuii
2026-02-19 18:53:04 +05:30
parent 94d0aabec6
commit ba2831d491
7 changed files with 174 additions and 2 deletions

View File

@@ -4,10 +4,17 @@ FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
COPY package*.json ./ COPY package*.json ./
RUN npm install RUN npm ci
COPY . . COPY . .
# Build-time env vars (Vite embeds these into the compiled JS bundle)
# Pass via: docker build --build-arg VITE_API_URL=https://api.yourdomain.com .
ARG VITE_API_URL=http://localhost:3000/api
ARG VITE_APP_NAME="VC E-Commerce Admin Panel"
ENV VITE_API_URL=$VITE_API_URL
ENV VITE_APP_NAME=$VITE_APP_NAME
RUN npm run build RUN npm run build
@@ -15,7 +22,8 @@ RUN npm run build
FROM nginx:alpine FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 5174 EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

20
k8s/configmap.yaml Normal file
View File

@@ -0,0 +1,20 @@
# NOTE: VITE_* variables are embedded into the JS bundle at build time by Vite.
# They cannot be changed at runtime without rebuilding the image.
#
# To deploy with a different API URL, rebuild the image with:
# docker build --build-arg VITE_API_URL=https://api.yourdomain.com \
# --build-arg VITE_APP_NAME="My Admin Panel" \
# -t your-registry/ecommerce-admin-panel:latest .
#
# This ConfigMap is provided for documentation and to store non-build-time
# configuration such as nginx tuning or future runtime injection.
apiVersion: v1
kind: ConfigMap
metadata:
name: ecommerce-admin-panel-config
namespace: ecommerce
labels:
app: ecommerce-admin-panel
data:
VITE_APP_NAME: "VC E-Commerce Admin Panel"
# VITE_API_URL must be set at build time — see note above

60
k8s/deployment.yaml Normal file
View File

@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecommerce-admin-panel
namespace: ecommerce
labels:
app: ecommerce-admin-panel
spec:
replicas: 2
selector:
matchLabels:
app: ecommerce-admin-panel
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
template:
metadata:
labels:
app: ecommerce-admin-panel
spec:
containers:
- name: ecommerce-admin-panel
# Replace with your actual registry image
# Build with: docker build --build-arg VITE_API_URL=https://api.yourdomain.com .
image: your-registry/ecommerce-admin-panel:latest
imagePullPolicy: Always
ports:
- containerPort: 80
protocol: TCP
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "200m"
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 30
failureThreshold: 3
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 3
# Spread pods across nodes for high availability
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: ecommerce-admin-panel

32
k8s/ingress.yaml Normal file
View File

@@ -0,0 +1,32 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ecommerce-admin-panel
namespace: ecommerce
labels:
app: ecommerce-admin-panel
annotations:
# Required for SPA: rewrite all paths to / so React Router handles routing
nginx.ingress.kubernetes.io/rewrite-target: /
# Enable gzip at the ingress level
nginx.ingress.kubernetes.io/enable-gzip: "true"
# Optional: enable HTTPS redirect (uncomment when TLS is configured)
# nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
ingressClassName: nginx
rules:
- host: admin.yourdomain.com # Replace with your actual domain
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ecommerce-admin-panel
port:
number: 80
# TLS (uncomment and configure when you have a TLS certificate / cert-manager)
# tls:
# - hosts:
# - admin.yourdomain.com
# secretName: ecommerce-admin-panel-tls

6
k8s/namespace.yaml Normal file
View File

@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: ecommerce
labels:
app: ecommerce-admin-panel

16
k8s/service.yaml Normal file
View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: ecommerce-admin-panel
namespace: ecommerce
labels:
app: ecommerce-admin-panel
spec:
selector:
app: ecommerce-admin-panel
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
type: ClusterIP

30
nginx.conf Normal file
View File

@@ -0,0 +1,30 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# SPA fallback: serve index.html for all client-side routes
location / {
try_files $uri $uri/ /index.html;
}
# Cache static assets aggressively (Vite fingerprints filenames)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 1024;
}