apiVersion: v1
kind: Service
metadata:
  name: octoprint
  labels:
    run: octoprint
spec:
  ports:
    - name: http
      port: 5000
      targetPort: 5000
  selector:
    run: octoprint
  type: LoadBalancer
status:
  loadBalancer: {}
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: octoprint
spec:
  capacity:
    storage: 100Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Kubernetes/volumes/static/octoprint
    server: 10.42.42.10
  claimRef:
    name: octoprint
    namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
#  labels:
#    run: octoprint
  name: octoprint
spec:
  storageClassName: default
#  volumeName: octoprint
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: octoprint
spec:
  replicas: 1
  selector:
    matchLabels:
      run: octoprint
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        run: octoprint
    spec:
      nodeSelector:
        octoprint: "true"
      containers:
        - image: octoprint/octoprint
          name: octoprint
          securityContext:
            privileged: true
          env:
          - name: OCTOPRINT_PORT
            value: "5000"
          ports:
            - containerPort: 5000
          resources: {}
          volumeMounts:
            - mountPath: /octoprint
              name: octoprint
            - mountPath: /dev/ttyUSB0
              name: ttyusb
      restartPolicy: Always
      volumes:
        - name: octoprint
          persistentVolumeClaim:
            claimName: octoprint
        - name: ttyusb
          hostPath: 
            path: /dev/ttyUSB0
status: {}
---
# Hosting
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: octoprint-ingress
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    ## No basic auth for octoprint
    ## 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 - Octoprint'
    # Octoprint uses large attachments
    nginx.ingress.kubernetes.io/proxy-body-size: 200m
spec:
  tls:
  - hosts:
    - octoprint.monkeybox.org
    secretName: octoprint-tls
  rules:
  - host: octoprint.monkeybox.org
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: octoprint
            port:
              number: 5000
