diff --git a/Dockerfile b/Dockerfile index bccd7c76..0e7e3e41 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,4 +53,5 @@ COPY --from=build /app/.next/static /app/.next/static COPY --from=build /app/prisma /app/prisma COPY --from=build /app/ecosystem.config.js /app/ecosystem.config.js -CMD ["pm2-runtime", "start", "-i", "2", "ecosystem.config.js"] +ENTRYPOINT [ "pm2-runtime" ] +CMD ["start", "-i", "2", "ecosystem.config.js"] diff --git a/deploy/dev/cm.yaml b/deploy/dev/cm.yaml index fb14566e..827b1e99 100644 --- a/deploy/dev/cm.yaml +++ b/deploy/dev/cm.yaml @@ -19,7 +19,7 @@ data: dns cloudflare {env.CF_API_TOKEN} } - reverse_proxy 127.0.0.1:3000 + reverse_proxy xlog-internal.crossbell.svc:3000 } :8080 { @@ -31,7 +31,7 @@ data: on_demand } - reverse_proxy 127.0.0.1:3000 + reverse_proxy xlog-internal.crossbell.svc:3000 } --- apiVersion: v1 diff --git a/deploy/dev/sts.yaml b/deploy/dev/deploy.yaml similarity index 73% rename from deploy/dev/sts.yaml rename to deploy/dev/deploy.yaml index 2a478781..63083fcc 100644 --- a/deploy/dev/sts.yaml +++ b/deploy/dev/deploy.yaml @@ -1,14 +1,20 @@ apiVersion: apps/v1 -kind: StatefulSet +kind: Deployment metadata: name: xlog namespace: crossbell spec: + progressDeadlineSeconds: 600 replicas: 1 - serviceName: "xlog-lb" + revisionHistoryLimit: 5 selector: matchLabels: app: xlog + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate template: metadata: labels: @@ -32,6 +38,11 @@ spec: - image: $IMAGE_TAG_RELEASE imagePullPolicy: Always name: xlog + args: + - "start" + - "-i" + - "1" + - "ecosystem.config.js" envFrom: - secretRef: name: xlog @@ -40,10 +51,10 @@ spec: protocol: TCP resources: requests: - memory: "6000Mi" + memory: "1000Mi" cpu: "300m" limits: - memory: "10000Mi" + memory: "3000Mi" cpu: "2000m" terminationMessagePath: /dev/termination-log terminationMessagePolicy: File @@ -58,14 +69,38 @@ spec: port: 3000 initialDelaySeconds: 40 periodSeconds: 20 - volumeMounts: - - name: data - mountPath: "/app/.next/cache/images" - subPath: images + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: xlog-caddy + namespace: crossbell +spec: + selector: + matchLabels: + app: xlog-caddy + template: + metadata: + labels: + app: xlog-caddy + spec: + containers: - name: caddy image: kindjeff/caddy-tlsredis-docker imagePullPolicy: Always command: ["caddy", "run", "-config", "/app/Caddyfile"] + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 100m + memory: 128Mi envFrom: - secretRef: name: xlog-caddy @@ -81,6 +116,13 @@ spec: image: python command: ["/bin/sh", "-c"] args: ["pip install flask requests; flask --app=app run"] + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 100m + memory: 128Mi ports: - containerPort: 5000 name: http @@ -88,11 +130,6 @@ spec: - name: validator mountPath: /app.py subPath: app.py - dnsPolicy: ClusterFirst - restartPolicy: Always - schedulerName: default-scheduler - securityContext: {} - terminationGracePeriodSeconds: 30 volumes: - name: caddyfile configMap: @@ -100,12 +137,3 @@ spec: - name: validator configMap: name: xlog-caddy-validator - volumeClaimTemplates: - - metadata: - name: data - spec: - accessModes: ["ReadWriteOnce"] - storageClassName: "alicloud-disk-ssd" - resources: - requests: - storage: 20Gi diff --git a/deploy/dev/svc.yaml b/deploy/dev/svc.yaml index 1bd63140..13975b68 100644 --- a/deploy/dev/svc.yaml +++ b/deploy/dev/svc.yaml @@ -9,7 +9,7 @@ metadata: spec: type: LoadBalancer selector: - app: xlog + app: xlog-caddy ports: - name: http protocol: TCP @@ -19,3 +19,18 @@ spec: protocol: TCP port: 443 targetPort: 443 +--- +apiVersion: v1 +kind: Service +metadata: + name: xlog-internal + namespace: crossbell +spec: + type: ClusterIP + selector: + app: xlog + ports: + - name: http + protocol: TCP + port: 3000 + targetPort: 3000 diff --git a/deploy/prod/cm.yaml b/deploy/prod/cm.yaml index a54c72c4..b4263e53 100644 --- a/deploy/prod/cm.yaml +++ b/deploy/prod/cm.yaml @@ -19,7 +19,7 @@ data: dns cloudflare {env.CF_API_TOKEN} } - reverse_proxy 127.0.0.1:3000 + reverse_proxy xlog-internal.crossbell.svc:3000 } :8080 { @@ -31,7 +31,7 @@ data: on_demand } - reverse_proxy 127.0.0.1:3000 + reverse_proxy xlog-internal.crossbell.svc:3000 } --- apiVersion: v1 diff --git a/deploy/prod/deploy.yaml b/deploy/prod/deploy.yaml index 56fb36cf..9a0b38cd 100644 --- a/deploy/prod/deploy.yaml +++ b/deploy/prod/deploy.yaml @@ -53,16 +53,13 @@ spec: protocol: TCP resources: requests: - memory: "6000Mi" + memory: "1000Mi" cpu: "300m" limits: - memory: "10000Mi" + memory: "3000Mi" cpu: "2000m" terminationMessagePath: /dev/termination-log terminationMessagePolicy: File - volumeMounts: - - name: xlog-image - mountPath: /app/.next/cache/images readinessProbe: httpGet: path: /api/healthcheck @@ -74,10 +71,39 @@ spec: port: 3000 initialDelaySeconds: 40 periodSeconds: 20 + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: xlog-caddy + namespace: crossbell +spec: + replicas: 3 + selector: + matchLabels: + app: xlog-caddy + template: + metadata: + labels: + app: xlog-caddy + spec: + containers: - name: caddy image: kindjeff/caddy-tlsredis-docker imagePullPolicy: Always command: ["caddy", "run", "-config", "/app/Caddyfile"] + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 100m + memory: 128Mi envFrom: - secretRef: name: xlog-caddy @@ -93,6 +119,13 @@ spec: image: python command: ["/bin/sh", "-c"] args: ["pip install flask requests; flask --app=app run"] + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 100m + memory: 128Mi ports: - containerPort: 5000 name: http @@ -100,18 +133,10 @@ spec: - name: validator mountPath: /app.py subPath: app.py - dnsPolicy: ClusterFirst - restartPolicy: Always - schedulerName: default-scheduler - securityContext: {} - terminationGracePeriodSeconds: 30 volumes: - name: caddyfile configMap: name: xlog-caddy - name: validator configMap: - name: xlog-caddy-validator - - name: xlog-image - persistentVolumeClaim: - claimName: xlog-image # OSS PVC created manually in the ACK console + name: xlog-caddy-validator \ No newline at end of file diff --git a/deploy/prod/hpa.yaml b/deploy/prod/hpa.yaml index f03c1387..a3407a21 100644 --- a/deploy/prod/hpa.yaml +++ b/deploy/prod/hpa.yaml @@ -1,13 +1,19 @@ -apiVersion: autoscaling/v1 +apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: xlog namespace: crossbell spec: maxReplicas: 11 - minReplicas: 8 + minReplicas: 7 scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: xlog - targetCPUUtilizationPercentage: 70 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 70