apiVersion: v1
kind: Service
metadata:
  name: go-ipfs-tcp
  labels:
    run: go-ipfs
  annotations:
    metallb.universe.tf/allow-shared-ip: "pihole"
spec:
  ports:
    - name: swarm
      protocol: TCP
      port: 4001
      targetPort: 4001
    - name: api
      protocol: TCP
      port: 5001
      targetPort: 5001
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
  selector:
    run: go-ipfs
  type: LoadBalancer
  loadBalancerIP: 10.42.42.236
  externalTrafficPolicy: Local
---
apiVersion: v1
kind: Service
metadata:
  name: go-ipfs-udp
  labels:
    run: go-ipfs
  annotations:
    metallb.universe.tf/allow-shared-ip: "pihole"
spec:
  ports:
    - name: swarm
      protocol: UDP
      port: 4001
      targetPort: 4001
  selector:
    run: go-ipfs
  type: LoadBalancer
  loadBalancerIP: 10.42.42.236
  externalTrafficPolicy: Local
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: go-ipfs-data
spec:
  capacity:
    storage: 5Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Kubernetes/volumes/static/go-ipfs-data
    server: 10.42.42.10
  claimRef:
    name: go-ipfs-data
    namespace: default

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: go-ipfs-data
  annotations:
    nfs.io/storage-path: "go-ipfs"
spec:
  storageClassName: default
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Mi
status: {}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: go-ipfs-staging
spec:
  capacity:
    storage: 5Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Kubernetes/volumes/static/go-ipfs-staging
    server: 10.42.42.10
  claimRef:
    name: go-ipfs-staging
    namespace: default

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: go-ipfs-staging
  annotations:
    nfs.io/storage-path: "go-ipfs"
spec:
  storageClassName: default
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Mi
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-ipfs
spec:
  replicas: 1
  selector:
    matchLabels:
      run: go-ipfs
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        run: go-ipfs
    spec:
      containers:
        #        - image: ipfs/go-ipfs:latest
        - image: yrzr/go-ipfs-arm64v8:latest
          name: go-ipfs
          ports:
            - containerPort: 4001
              protocol: TCP
            - containerPort: 4001
              protocol: UDP
            - containerPort: 5001
              protocol: TCP
            - containerPort: 8080
              protocol: TCP
          resources: {}
          volumeMounts:
            - mountPath: /data/ipfs
              name: go-ipfs-data
            - mountPath: /export
              name: go-ipfs-staging
      restartPolicy: Always
# This didn't seem to do what I want/need
#      affinity:
#        podAntiAffinity:                                 
#          requiredDuringSchedulingIgnoredDuringExecution:  #<---- hard requirement not to schedule "nginx" pod if already one scheduled.
#          - topologyKey: kubernetes.io/hostname    # <---- Anti affinity scope is host     
#            labelSelector:                               
#              matchLabels:                               
#                app: go-ipfs
#      topologySpreadConstraints:
#        - maxSkew: 1
#          topologyKey: kubernetes.io/hostname
#          whenUnsatisfiable: DoNotSchedule
#          labelSelector:
#            matchLabels:
#              app: go-ipfs
      volumes:
        - name: go-ipfs-data
          persistentVolumeClaim:
            claimName: go-ipfs-data
        - name: go-ipfs-staging
          persistentVolumeClaim:
            claimName: go-ipfs-staging
status: {}
---
# Hosting
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: go-ipfs-ingress
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    ## basic auth for go-ipfs
    # type of authentication
    #nginx.ingress.kubernetes.io/auth-type: basic
    # name of the secret that contains the user/password definitions
    #nginx.ingress.kubernetes.io/auth-secret: basic-auth
    # message to display with an appropriate context why the authentication is required
    #nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - Go-IPFS'
spec:
  tls:
  - hosts:
    - ipfs.monkeybox.org
    secretName: go-ipfs-tls
  rules:
  - host: ipfs.monkeybox.org
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: go-ipfs
            port:
              number: 8080
