apiVersion: apps/v1
kind: Deployment
metadata:
  name: ml-deployment
  namespace: default
  labels:
    app: ml-api
    project: PROJECT_ID
    commit_sha: COMMIT_SHA
spec:
  replicas: 2
  minReadySeconds: 5
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  selector:
    matchLabels:
      app: ml-api
  template:
    metadata:
      name: ml-pod
      labels:
        app: ml-api
    spec:
      containers:
      # [START My container]
      - name: ml-container
        image: gcr.io/PROJECT_ID/gkecicd:COMMIT_SHA
        ports:
          - containerPort: 8080
        lifecycle:
          preStop:
            exec:
              command: [ "sh", "-c", "sleep 5" ]
        readinessProbe:
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1
          httpGet:
            path: /check
            port: 8080
      # [END My container]
      # [START Extensible Service Proxy (ESP)]
      - name: esp
        image: gcr.io/endpoints-release/endpoints-runtime:1
        args: [
          "--http_port", "8081",
          "--backend", "127.0.0.1:8080",
          "--service", "SERVICE_NAME.endpoints.PROJECT_ID.cloud.goog",
          "--rollout_strategy", "managed",
        ]
        ports:
        - containerPort: 8081
      # [END Extensible Service Proxy (ESP)]