---
apiVersion: v1
kind: Namespace
metadata:
  name: prod
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  namespace: prod
  name: api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: api
      tier: frontend
  template:
    metadata:
      labels:
        app: api
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: busybox
        command:
        - /bin/sh
        - "-c"
        - |
          i=0;
          while true; do
            echo "GET /users/$i
          no-cache";
            sleep 1;
            i=$((i + 1));
          done
      - name: cache
        image: busybox
        command:
        - /bin/sh
        - "-c"
        - i=0; while true; do echo "evict users.$i"; sleep 2; i=$((i + 1)); done
---
kind: Service
apiVersion: v1
metadata:
  namespace: prod
  name: api
spec:
  type: NodePort
  selector:
    app: api
    tier: frontend
  ports:
    - protocol: TCP
      port: 4200
      targetPort: http
---
apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
  namespace: prod
  name: workers
spec:
  selector:
    matchLabels:
      app: api
      tier: backend
      component: worker
  template:
    metadata:
      name: workers
      labels:
        app: api
        tier: backend
        component: worker
    spec:
      containers:
      - name: statistics
        image: busybox
        command:
        - /bin/sh
        - "-c"
        - i=0; while true; do echo "processing user $1 stats..."; sleep 1; i=$((i + 1)); done
      - name: thumbnails
        image: busybox
        command:
        - /bin/sh
        - "-c"
        - i=0; while true; do echo "creating user $1 thumbnail..."; sleep 2; i=$((i + 1)); done
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: prod
  name: api
spec:
  backend:
    serviceName: api
    servicePort: 4200
