#
# Balancer scaling 2 deployments using 50/50 proportional policy.
#
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-1
  labels:
    app: nginx-1
    srv: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-1
      srv: nginx
  template:
    metadata:
      labels:
        app: nginx-1
        srv: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-2
  labels:
    app: nginx-2
    srv: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-2
      srv: nginx
  template:
    metadata:
      labels:
        app: nginx-2
        srv: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: balancer.x-k8s.io/v1alpha1
kind: Balancer
metadata:
  name: nginx
spec:
  replicas: 10
  selector:
    matchLabels:
      srv: nginx
  policy:
    policyName: proportional
    proportions:
      targetProportions:
        nginx-1: 50
        nginx-2: 50
    fallback:
      startupTimeoutSeconds: 180
  targets:
    - name: nginx-1
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: nginx-1
      minReplicas: 1
      maxReplicas: 7
    - name: nginx-2
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: nginx-2
      minReplicas: 1
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    srv: nginx
