apiVersion: apps/v1
kind: Deployment
metadata:
  name: capstone-app
  labels:
    app: capstone-app
spec:
  selector:
    matchLabels:
      app: capstone-app
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  progressDeadlineSeconds: 1200
  minReadySeconds: 60
  template:
    metadata:
      labels:
        app: capstone-app
    spec:
      terminationGracePeriodSeconds: 60
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: "app"
                operator: In
                values:
                - capstone-app
              - key: "temporary"
                operator: In
                values:
                - "true"
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: capstone
        image: nilay16/capstone:v1
        command: [
          "/bin/bash", 
          "run_docker.sh"
          ]
        imagePullPolicy: Always
        resources:
          limits:
            memory: 64Mi
            cpu: 250m
          requests:
            memory: 32Mi
            cpu: 200m
        ports:
        - containerPort: 80
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            scheme: HTTP
            port: 80
          periodSeconds: 10
          successThreshold: 1
          failureThreshold: 2
          timeoutSeconds: 1


apiVersion: v1
kind: Service
metadata:
  name: capstone-app
spec:
  type: LoadBalancer
  selector:
    app: capstone-app
  ports:
    - name: helloword-http
      protocol: TCP
      port: 80
      targetPort: 80
    - name: helloword-https
      protocol: TCP
      port: 443
      targetPort: 443
      

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v1
metadata:
  name: capstone-app
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: capstone-app
  minReplicas: 2
  maxReplicas: 5
  targetCPUUtilizationPercentage: 80

