front_re.sh 2.49 KB
# 切换到您的自定义前端镜像
kubectl patch deployment -n ecommerce frontend -p '{
  "spec": {
    "template": {
      "spec": {
        "containers": [{
          "name": "frontend",
          "image": "319998871902.dkr.ecr.us-east-1.amazonaws.com/ecommerce-frontend:1.1.2",
          "command": null,
          "args": null,
          "env": [
            {
              "name": "NODE_ENV",
              "value": "production"
            },
            {
              "name": "PORT",
              "value": "80"
            },
            {
              "name": "API_BASE_URL", 
              "value": "https://api.awsmpc.asia"
            },
            {
              "name": "REACT_APP_API_URL",
              "value": "https://api.awsmpc.asia"
            }
          ],
          "volumeMounts": [
            {
              "name": "nginx-config",
              "mountPath": "/etc/nginx/conf.d/default.conf",
              "subPath": "nginx.conf"
            },
            {
              "name": "environment-config",
              "mountPath": "/usr/share/nginx/html/env.js",
              "subPath": "environment.js"
            }
          ],
          # 使用 /health 端点进行健康检查(您的镜像应该有这个端点)
          "livenessProbe": {
            "httpGet": {
              "path": "/health",
              "port": 80
            },
            "initialDelaySeconds": 30,
            "periodSeconds": 10,
            "timeoutSeconds": 5,
            "failureThreshold": 3
          },
          "readinessProbe": {
            "httpGet": {
              "path": "/health",
              "port": 80
            },
            "initialDelaySeconds": 5,
            "periodSeconds": 5,
            "timeoutSeconds": 3,
            "failureThreshold": 3
          },
          "startupProbe": {
            "httpGet": {
              "path": "/health",
              "port": 80
            },
            "initialDelaySeconds": 10,
            "periodSeconds": 10,
            "failureThreshold": 30
          }
        }]
      }
    }
  }
}'

# 添加 volumes
kubectl patch deployment -n ecommerce frontend -p '{
  "spec": {
    "template": {
      "spec": {
        "volumes": [
          {
            "name": "nginx-config",
            "configMap": {
              "name": "frontend-config"
            }
          },
          {
            "name": "environment-config",
            "configMap": {
              "name": "frontend-config"
            }
          }
        ]
      }
    }
  }
}'