# If you are running Kubernetes >= 1.1.0. You can take advantage of DaemonSets to automatically deploy the Pumba on all your nodes.
# On 1.1.x you'll need to explicitly enable the DaemonSets extension, see http://kubernetes.io/v1.1/docs/admin/daemons.html#caveats.

# You'll then be able to deploy the DaemonSet with the command
# `kubectl create -f pumba_kube.yaml`

# If you are not running Kubernetes >= 1.1.0 or do not want to use DaemonSets, you can also run the Pumba as a regular docker container on each node you want to make chaos.
# `docker run -d -v /var/run/docker.sock:/var/run/docker.sock gaiaadm/pumba pumba --random --interval 3m kill --signal SIGKILL"`

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: pumba
spec:
  selector:
    matchLabels:
      app: pumba
  template:
    metadata:
      labels:
        app: pumba
        com.gaiaadm.pumba: "true" # prevent pumba from killing itself
      name: pumba
    spec:
      containers:
      # randomly pause containers in Pod named 'test-1' every minute for 30 sec
      - image: gaiaadm/pumba
        imagePullPolicy: Always
        name: pumba-pause
        args:
          - --random
          - --log-level
          - info
          - --label
          - io.kubernetes.pod.name=test-1
          - --interval
          - 20s
          - pause
          - --duration 
          - 10s
        resources:
          requests:
            cpu: 10m
            memory: 5M
          limits:
            cpu: 100m
            memory: 20M
        volumeMounts:
          - name: dockersocket
            mountPath: /var/run/docker.sock
      # randomly add a  3000ms ± 30ms delay to 'test-2' Pod containers every 5m for 2m, where variation in delay is described by `normal` distribution,
      - image: gaiaadm/pumba
        imagePullPolicy: Always
        name: pumba-delay
        args:
          - --random
          - --log-level
          - info
          - --label
          - io.kubernetes.pod.name=test-2
          - --interval
          - 30s
          - netem
          - --duration
          - 20s
          - --tc-image
          - gaiadocker/iproute2
          - delay
          - --time
          - "3000"
          - --jitter
          - "30"
          - --distribution 
          - normal
        resources:
          requests:
            cpu: 10m
            memory: 5M
          limits:
            cpu: 100m
            memory: 20M
        volumeMounts:
          - name: dockersocket
            mountPath: /var/run/docker.sock
      # limit to specific k8s nodes
      # EKS node group
      # nodeSelector:
      #     alpha.eksctl.io/nodegroup-name=my-node-group
      # GKE node pool
      # nodeSelector:
      #     cloud.google.com/gke-nodepool=node-pool
      volumes:
        - hostPath:
            path: /var/run/docker.sock
          name: dockersocket
