apiVersion: apps/v1
kind: Deployment
metadata:
  name: vpn-downloader
spec:
  selector:
    matchLabels:
      app: vpn-downloader
  replicas: 1
  revisionHistoryLimit: 0
  strategy:
    type: Recreate
  template:
    metadata:
      name: vpn-downloader
      labels:
        app: vpn-downloader
    spec:
      hostname: vpn-downloader
      nodeSelector: #Only schedule in the big server
        kubernetes.io/hostname: server.angelnu.com
      containers:
      - name: vpn-downloader
        image: ubuntu:latest
        imagePullPolicy: Always
        command:
        - "/bin/sh"
        - "-c"
        - |
          trap 'exit' INT TERM
          while [ 1 ]; do
            sleep 600 &
            wait $!
          done
        env:
        - name: TZ
          value: Europe/Berlin
        volumeMounts:
        - mountPath: /downloads
          name: data
# VPN boiler-plate 1 (insert at the end of volumeMounts)
        - name: resolv
          mountPath: /etc/resolv.conf
          subPath: resolv.conf
      - name: vxlan
        image: angelnu/openvpn-helper
        imagePullPolicy: Always
        securityContext:
          capabilities:
            add:
              - NET_ADMIN
        volumeMounts:
        - name: resolv
          mountPath: /etc_shared
# end of VPN boiler-plate 1
      volumes:
      - name: config
        persistentVolumeClaim:
          claimName: nfs-kubernetes
      - name: data
        flexVolume:
          driver: "angelnu/cifs"
          secretRef:
            name: "cifs-secret"
          options:
            source: "//nas.home.angelnu.com/downloads"
            mountOptions: "dir_mode=0775,file_mode=0664,noperm"

# VPN boiler-plate 2 (append at the end of the volumes section)
      - name: resolv
        emptyDir: {}
      initContainers:
      - name: init-vxlan
        image: angelnu/openvpn-helper
        imagePullPolicy: Always
        securityContext:
          capabilities:
            add:
              - NET_ADMIN
        env:
        - name: FIRST_BOOT
          value: "true"
        volumeMounts:
        - name: resolv
          mountPath: /etc_shared
# end of VPN boiler-plate 2
