---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: busybox-local-sts
spec:
  replicas: 3
  serviceName: ""
  selector:
    matchLabels:
      app: busybox-local-sts
  template:
    metadata:
      labels:
        app: busybox-local-sts
    spec:
      affinity:
        #Use node affinity if the nodes are labelled as follows:
        # kubectl label node gke-kmova-helm-default-pool-6597c2bc-n9kn openebs.io/node-type=storage
        #nodeAffinity:
        #  requiredDuringSchedulingIgnoredDuringExecution:
        #    nodeSelectorTerms:
        #    - matchExpressions:
        #      - key: openebs.io/node-type
        #        operator: In
        #        values:
        #        - storage
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              topologyKey: node
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                    - busybox-local-sts
          #requiredDuringSchedulingIgnoredDuringExecution:
          #- labelSelector:
          #    matchLabels:
          #      app: busybox-local-sts
          #  topologyKey: kubernetes.io/hostname
      containers:
      - name: busybox
        image: busybox
        command:
          - sh
          - -c
          - 'echo `date` from `hostname` >> /mnt/store/date.txt; mkdir /mnt/store/sub-dir1; sync; sleep 5; sync; tail -f /dev/null;'
        volumeMounts:
        - mountPath: /mnt/store
          name: demo-local-sts
  volumeClaimTemplates:
  - metadata:
      name: demo-local-sts
    spec:
      accessModes:
      - ReadWriteOnce
      storageClassName: openebs-local-sts
      resources:
        requests:
          storage: 4G
