# PVC backed by NFS server
#
# For K8s environments other than GKE, you will need to modify the nfs-storage
# persistent volume to reference directly the IP address of the nfs-server:
# 1. Deploy the nfs-server resources
# 2. Get the IP address of the nfs-server with `kubectl get service nfs-server`
# 3. Replace `nfs-server.tower-nf.svc.cluster.local` with the IP address in the nfs-storage YAML
# 4. Deploy the nfs-storage PV and tower-scratch PVC
#
# For more information, see https://github.com/kubernetes/minikube/issues/3417#issuecomment-670005434

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nfs-server
  namespace: tower-nf
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: standard

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-server
  namespace: tower-nf
spec:
  replicas: 1
  selector:
    matchLabels:
      role: nfs-server
  template:
    metadata:
      labels:
        role: nfs-server
    spec:
      containers:
      - name: nfs-server
        image: gcr.io/google_containers/volume-nfs:0.8
        ports:
          - name: nfs
            containerPort: 2049
          - name: mountd
            containerPort: 20048
          - name: rpcbind
            containerPort: 111
        securityContext:
          privileged: true
        volumeMounts:
          - mountPath: /exports
            name: vol-1
      volumes:
        - name: vol-1
          persistentVolumeClaim:
            claimName: nfs-server

---

apiVersion: v1
kind: Service
metadata:
  name: nfs-server
  namespace: tower-nf
spec:
  ports:
    - name: nfs
      port: 2049
    - name: mountd
      port: 20048
    - name: rpcbind
      port: 111
  selector:
    role: nfs-server

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-storage
  namespace: tower-nf
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    # For K8s environments other than GKE, the nfs-server IP address must be used
    server: nfs-server.tower-nf.svc.cluster.local
    path: "/"

---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: tower-scratch
  namespace: tower-nf
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 10Gi
