Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions deploy/azure/06-AZURE-DEPLOY-SERVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,67 @@ exit

## Troubleshooting

### API Gateway Service no se crea

**Síntoma:** El pod del API Gateway está Running pero no aparece el Service en `kubectl get svc -n fuel-system`

**Causa:** Error silencioso durante el apply de Helm, generalmente por timeout esperando la IP del LoadBalancer

**Solución:**

```bash
# 1. Verificar si el Service existe
kubectl get svc fuel-system-api-gateway -n fuel-system

# Si no existe, crearlo manualmente:
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: fuel-system-api-gateway
namespace: fuel-system
labels:
app.kubernetes.io/name: fuel-system
app.kubernetes.io/instance: fuel-system
app.kubernetes.io/component: api-gateway
app.kubernetes.io/managed-by: Helm
spec:
type: LoadBalancer
ports:
- port: 8080
targetPort: http
protocol: TCP
name: http
- port: 443
targetPort: https
protocol: TCP
name: https
selector:
app.kubernetes.io/name: fuel-system
app.kubernetes.io/instance: fuel-system
app.kubernetes.io/component: api-gateway
EOF

# 2. Verificar que obtuvo IP pública (tarda 1-2 minutos)
kubectl get svc fuel-system-api-gateway -n fuel-system -w

# 3. Una vez que tenga EXTERNAL-IP, probar
export API_IP=$(kubectl get svc fuel-system-api-gateway -n fuel-system -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
curl http://$API_IP:8080/health
```

**Prevención:** Aumentar el timeout de Helm:

```bash
helm upgrade --install fuel-system ./deploy/helm/fuel-system \
--namespace fuel-system \
--values ./deploy/helm/fuel-system/values.yaml \
--values ./deploy/azure/values-azure.yaml \
--wait \
--timeout 20m \ # Aumentado de 15m a 20m
--debug
```

### Pods en CrashLoopBackOff

```bash
Expand Down Expand Up @@ -472,6 +533,61 @@ kubectl get configmap fuel-system-config -n fuel-system -o yaml | grep EUREKA
kubectl rollout restart deployment -n fuel-system
```

### Error "Missing credentials for PLAIN" en recuperación de contraseña

**Síntoma:** El login funciona correctamente pero la recuperación de contraseña falla con error `Missing credentials for "PLAIN"`

**Causa:** El email-service no puede autenticarse con el servidor SMTP. Esto puede ser porque:
- Las credenciales SMTP no están configuradas correctamente
- El secret no existe o tiene formato incorrecto
- Las variables de entorno no coinciden con las del código

**Solución:**

```bash
# 1. Verificar que el secret SMTP existe y tiene los valores correctos
kubectl get secret fuel-system-smtp -n fuel-system -o jsonpath="{.data.host}" | base64 --decode && echo
kubectl get secret fuel-system-smtp -n fuel-system -o jsonpath="{.data.port}" | base64 --decode && echo
kubectl get secret fuel-system-smtp -n fuel-system -o jsonpath="{.data.user}" | base64 --decode && echo
kubectl get secret fuel-system-smtp -n fuel-system -o jsonpath="{.data.password}" | base64 --decode && echo

# 2. Si el secret no existe o es incorrecto, crearlo:
kubectl delete secret fuel-system-smtp -n fuel-system 2>/dev/null || true

# Para Gmail con App Password:
kubectl create secret generic fuel-system-smtp \
--from-literal=host='smtp.gmail.com' \
--from-literal=port='587' \
--from-literal=user='tu-email@gmail.com' \
--from-literal=password='tu-app-password-de-16-caracteres' \
--namespace=fuel-system

# NOTA: Para Gmail necesitas generar una App Password en:
# https://myaccount.google.com/apppasswords
# (requiere tener 2FA habilitado)

# 3. Verificar las variables de entorno en el pod
kubectl exec -it deployment/fuel-system-email-service -n fuel-system -- sh
# Dentro del pod:
env | grep SMTP
# Debe mostrar: SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS
exit

# 4. Reiniciar el email-service para que tome las nuevas credenciales
kubectl rollout restart deployment/fuel-system-email-service -n fuel-system

# 5. Ver logs para verificar
kubectl logs -f deployment/fuel-system-email-service -n fuel-system

# 6. Probar recuperación de contraseña
INGRESS_IP=$(kubectl get svc ingress-nginx-controller -n ingress-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
curl -X POST http://$INGRESS_IP/auth/recover-password \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com"}'
```

**Prevención:** Asegúrate de crear el secret SMTP **antes** de desplegar con Helm, o usa valores correctos en `values-azure.yaml` para que Helm lo cree automáticamente.

### ImagePullBackOff

```bash
Expand Down
54 changes: 40 additions & 14 deletions deploy/helm/fuel-system/templates/auth-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,49 @@ spec:
app.kubernetes.io/component: auth-service
spec:
{{- include "fuel-system.imagePullSecrets" . | nindent 6 }}
# Init Container para esperar a que la base de datos esté disponible
# Auth-service usa TypeORM con synchronize:true, no necesita SQL manual
initContainers:
- name: wait-for-db
- name: create-tables
image: postgres:15-alpine
command:
- sh
- -c
- |
set -e
echo "🔄 Waiting for auth database to be ready..."
echo "[Auth Init] Waiting for auth database to be ready..."
{{- $sslMode := .Values.postgresql.external.sslMode | default "disable" }}

{{- if eq $sslMode "require" }}
CONN_STRING="postgresql://${AUTH_DB_USER}:${AUTH_DB_PASS}@${AUTH_DB_HOST}:${AUTH_DB_PORT}/${AUTH_DB_NAME}?sslmode=require"
{{- else }}
CONN_STRING="postgresql://${AUTH_DB_USER}:${AUTH_DB_PASS}@${AUTH_DB_HOST}:${AUTH_DB_PORT}/${AUTH_DB_NAME}?sslmode=disable"
{{- end }}

for i in $(seq 1 30); do
{{- if eq $sslMode "require" }}
if PGPASSWORD="${AUTH_DB_PASS}" psql "sslmode=require host=${AUTH_DB_HOST} port=${AUTH_DB_PORT} user=${AUTH_DB_USER} dbname=${AUTH_DB_NAME}" -c '\q' 2>/dev/null; then
{{- else }}
if PGPASSWORD="${AUTH_DB_PASS}" psql -h "${AUTH_DB_HOST}" -p "${AUTH_DB_PORT}" -U "${AUTH_DB_USER}" -d "${AUTH_DB_NAME}" -c '\q' 2>/dev/null; then
{{- end }}
echo "✅ Auth database is ready!"
exit 0
if psql "${CONN_STRING}" -c '\q' 2>/dev/null; then
echo "[Auth Init] Database connection successful"
break
fi
echo "Waiting for auth database... ($i/30)"
echo "[Auth Init] Waiting for database... (attempt $i/30)"
sleep 2
done
echo "❌ ERROR: Auth database no disponible después de 60 segundos"
exit 1

echo "[Auth Init] Creating verification_tokens table..."
psql "${CONN_STRING}" <<'EOF'
CREATE TABLE IF NOT EXISTS verification_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
"userId" INTEGER NOT NULL,
"tokenHash" VARCHAR(255) NOT NULL,
"expiresAt" TIMESTAMP NOT NULL,
used BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_verification_tokens_token ON verification_tokens("tokenHash");
CREATE INDEX IF NOT EXISTS idx_verification_tokens_user ON verification_tokens("userId");
CREATE INDEX IF NOT EXISTS idx_verification_tokens_expires ON verification_tokens("expiresAt");
EOF

echo "[Auth Init] Tables created successfully"
env:
- name: AUTH_DB_HOST
{{- if .Values.postgresql.external.hosts }}
Expand Down Expand Up @@ -264,6 +281,15 @@ spec:
name: {{ include "fuel-system.fullname" . }}-config
key: POSTGRESQL_SSL_REJECT_UNAUTHORIZED

# ========== CRITICAL: gRPC Server Configuration ==========
# These variables prevent SASL authentication issues
- name: GRPC_VERBOSITY
value: "ERROR"
- name: GRPC_TRACE
value: ""
- name: GRPC_ENABLE_FORK_SUPPORT
value: "1"

resources:
{{- toYaml .Values.authService.resources | nindent 10 }}
---
Expand Down
7 changes: 6 additions & 1 deletion deploy/helm/fuel-system/templates/microservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,16 @@ spec:
secretKeyRef:
name: {{ include "fuel-system.fullname" $ }}-smtp
key: user
- name: SMTP_PASSWORD
- name: SMTP_PASS
valueFrom:
secretKeyRef:
name: {{ include "fuel-system.fullname" $ }}-smtp
key: password
- name: FRONTEND_URL
valueFrom:
configMapKeyRef:
name: {{ include "fuel-system.fullname" $ }}-config
key: FRONTEND_URL
{{- end }}
resources:
{{- toYaml $config.config.resources | nindent 10 }}
Expand Down
1 change: 1 addition & 0 deletions deploy/helm/fuel-system/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ authService:
GRPC_PORT: 50052
AUTH_GRPC_PORT: 50052
DB_NAME: auth_db
DB_SYNCHRONIZE: "false"
database:
enabled: false
resources:
Expand Down
6 changes: 4 additions & 2 deletions services/api-gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ COPY protos/*.proto ./protos/
FROM node:20-alpine
WORKDIR /app

# Instalar curl para healthchecks
RUN apk add --no-cache curl
# Instalar curl para healthchecks y tzdata para timezone
RUN apk add --no-cache curl tzdata

# Configurar timezone
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
4 changes: 4 additions & 0 deletions services/auth-svc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ COPY protos ./protos
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar tzdata para timezone
RUN apk add --no-cache tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
5 changes: 3 additions & 2 deletions services/driver-ms/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ COPY protos/users.proto ./protos/users.proto
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar postgresql-client para ejecutar seeds
RUN apk add --no-cache postgresql-client
# Instalar postgresql-client para ejecutar seeds y tzdata para timezone
RUN apk add --no-cache postgresql-client tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
4 changes: 4 additions & 0 deletions services/email-svc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ COPY protos/email.proto ./protos/email.proto
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar tzdata para timezone
RUN apk add --no-cache tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
4 changes: 4 additions & 0 deletions services/fuel-svc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ COPY protos ./protos
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar tzdata para timezone
RUN apk add --no-cache tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
4 changes: 4 additions & 0 deletions services/hello-svc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ RUN npm run build
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar tzdata para timezone
RUN apk add --no-cache tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar dependencias de producción
Expand Down
5 changes: 3 additions & 2 deletions services/logger-svc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ RUN npm run build
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar curl para healthchecks
RUN apk add --no-cache curl
# Instalar curl para healthchecks y tzdata para timezone
RUN apk add --no-cache curl tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar dependencias de producción
Expand Down
4 changes: 4 additions & 0 deletions services/publisher-rabbit-srv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ COPY protos/logs.proto ./protos/logs.proto
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar tzdata para timezone
RUN apk add --no-cache tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
5 changes: 3 additions & 2 deletions services/routes-srv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ COPY protos ./protos
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar postgresql-client para ejecutar init.sql
RUN apk add --no-cache postgresql-client
# Instalar postgresql-client para ejecutar init.sql y tzdata para timezone
RUN apk add --no-cache postgresql-client tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
5 changes: 3 additions & 2 deletions services/users-srv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ COPY protos/users.proto ./protos/users.proto
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar OpenSSL para Prisma
RUN apk add --no-cache openssl
# Instalar OpenSSL para Prisma y tzdata para timezone
RUN apk add --no-cache openssl tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down
5 changes: 3 additions & 2 deletions services/vehicles-svc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ COPY protos ./protos
FROM node:20-alpine AS runtime
WORKDIR /app

# Instalar OpenSSL para Prisma
RUN apk add --no-cache openssl
# Instalar OpenSSL para Prisma y tzdata para timezone
RUN apk add --no-cache openssl tzdata

# Variables de entorno
ENV TZ=America/Guayaquil
ENV NODE_ENV=production

# Copiar package.json
Expand Down