Namespace

  apiVersion: v1
  kind: Namespace
  metadata:
    name: lobsters

PersistentVolume

  apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: lobsters
    namespace: lobsters
  spec:
    capacity:
      storage: 20Gi
    # volumeMode field requires BlockVolume Alpha feature gate to be enabled.
    volumeMode: Filesystem
    accessModes:
    - ReadWriteMany
    persistentVolumeReclaimPolicy: Retain
    local:
      path: /mnt/lobsters
    nodeAffinity:
      required:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/hostname
            operator: In
            values:
            - tom

PersistentVolumeClaim

  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: lobsters-mysql-claim
    namespace: lobsters
    labels:
      app: lobsters
  spec:
    accessModes:
      - ReadWriteMany
    resources:
      requests:
        storage: 20Gi

Deployment

  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    labels:
      app: mysql
    name: mysql
    namespace: lobsters
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          app: mysql
        name: mysql
      spec:
        containers:
          - name: mysql
            image: mysql:5.6.32
            env:
              - name: MYSQL_ROOT_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: lobsters
                    key: root-password
              - name: MYSQL_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: lobsters
                    key: mysql-password
              - name: MYSQL_USER
                value: lobsters
              - name: MYSQL_DATABASE
                value: lobsters
            ports:
              - name: mysql
                containerPort: 3306
            volumeMounts:
              - mountPath: /var/lib/mysql
                name: mysql
        volumes:
          - name: "mysql"
            persistentVolumeClaim:
              claimName: lobsters-mysql-claim

Service

  apiVersion: v1
  kind: Service
  metadata:
    labels:
      app: lobsters
    name: lobsters
    namespace: lobsters
  spec:
    ports:
    - port: 3000
      protocol: TCP
      targetPort: 3000
      nodePort: 30003
    selector:
      app: lobsters
    type: LoadBalancer

CronJob with hostPath volume

  apiVersion: batch/v1beta1
  kind: CronJob
  metadata:
    name: sync-lichess
    namespace: sync-lichess
  spec:
    # every day at 1 am
    schedule: "0 1 * * *"
    concurrencyPolicy: Replace
    jobTemplate:
      spec:
        template:
          spec:
            volumes:
              - name: lichess-volume
                hostPath:
                  path: /mnt/data/pgns/
            containers:
              - name: sync-lichess
                image: docker.io/reedrichards/sync-lichess:70475835
                volumeMounts:
                  - mountPath: /mnt/data/pgns
                    name: lichess-volume
                envFrom:
                  - secretRef:
                      name: lichess-secrets
            restartPolicy: OnFailure