apiVersion: v1
kind: Service
metadata:
  name: api
  labels:
    name: api
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 3000
    targetPort: 3000
  selector:
    name: heroes-api
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name:  heroes-api-deploy
  labels:
    name:  heroes-api
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        name:  heroes-api
    spec:
      imagePullSecrets:
        - name: acr-secret
      containers:
      - image: chzbrgr71/rating-api:osba
        name:  heroes-api-cntnr
        resources:
          requests:
            cpu: "20m"
            memory: "55M"
        env:
        - name: MONGODB_HOST
          valueFrom:
            secretKeyRef:
              name: heroes-cosmosdb-secret
              key: host
        - name: MONGODB_PORT
          valueFrom:
            secretKeyRef:
              name: heroes-cosmosdb-secret
              key: port
        - name: MONGODB_USERNAME
          valueFrom:
            secretKeyRef:
              name: heroes-cosmosdb-secret
              key: username
        - name: MONGODB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: heroes-cosmosdb-secret
              key: password
        - name: MONGODB_DBNAME
          value: "heroratings"
        ports:
        - containerPort:  3000
          name:  heroes-api
        imagePullPolicy: Always
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    name: web
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 8080
    targetPort: 8080
  selector:
    name: heroes-web
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name:  heroes-web-deploy
  labels:
    name:  heroes-web
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        name:  heroes-web
    spec:
      imagePullSecrets:
        - name: acr-secret
      containers:
      - image: chzbrgr71/rating-web:osba
        name:  heroes-web-cntnr
        resources:
          requests:
            cpu: "0.5"
            memory: "1Gi"
        env:
        - name:  API
          value:  http://api:3000/
        - name: KUBE_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: KUBE_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: KUBE_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        ports:
        - containerPort:  8080
          name:  heroes-web
        imagePullPolicy: Always
      restartPolicy: Always
---
apiVersion: servicecatalog.k8s.io/v1beta1
kind: ServiceInstance
metadata:
  name: heroes-cosmosdb-instance
  namespace: default
spec:
  clusterServiceClassExternalName: azure-cosmosdb-mongo-account
  parameters:
    location: eastus
    resourceGroup: heroes-cosmosdb
---
apiVersion: servicecatalog.k8s.io/v1beta1
kind: ServiceBinding
metadata:
  name: heroes-cosmosdb-binding
  namespace: default
spec:
  instanceRef:
    name: heroes-cosmosdb-instance
  secretName: heroes-cosmosdb-secret
---