From ba2831d491907175f7d74a5cce9e3338e69a747f Mon Sep 17 00:00:00 2001 From: tusuii Date: Thu, 19 Feb 2026 18:53:04 +0530 Subject: [PATCH] admin pannel k8s --- Dockerfile | 12 +++++++-- k8s/configmap.yaml | 20 +++++++++++++++ k8s/deployment.yaml | 60 +++++++++++++++++++++++++++++++++++++++++++++ k8s/ingress.yaml | 32 ++++++++++++++++++++++++ k8s/namespace.yaml | 6 +++++ k8s/service.yaml | 16 ++++++++++++ nginx.conf | 30 +++++++++++++++++++++++ 7 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 k8s/configmap.yaml create mode 100644 k8s/deployment.yaml create mode 100644 k8s/ingress.yaml create mode 100644 k8s/namespace.yaml create mode 100644 k8s/service.yaml create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index a567462..c652f3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,10 +4,17 @@ FROM node:20-alpine AS builder WORKDIR /app COPY package*.json ./ -RUN npm install +RUN npm ci 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 @@ -15,7 +22,8 @@ RUN npm run build FROM nginx:alpine 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;"] diff --git a/k8s/configmap.yaml b/k8s/configmap.yaml new file mode 100644 index 0000000..bb67672 --- /dev/null +++ b/k8s/configmap.yaml @@ -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 diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..46fc5a7 --- /dev/null +++ b/k8s/deployment.yaml @@ -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 diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml new file mode 100644 index 0000000..d4414db --- /dev/null +++ b/k8s/ingress.yaml @@ -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 diff --git a/k8s/namespace.yaml b/k8s/namespace.yaml new file mode 100644 index 0000000..1dcd215 --- /dev/null +++ b/k8s/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: ecommerce + labels: + app: ecommerce-admin-panel diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..0e0a153 --- /dev/null +++ b/k8s/service.yaml @@ -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 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..6ef1857 --- /dev/null +++ b/nginx.conf @@ -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; +}