diff --git a/docs/service.kubernetes.md b/docs/service.kubernetes.md index a2ea96d..5985723 100644 --- a/docs/service.kubernetes.md +++ b/docs/service.kubernetes.md @@ -25,12 +25,22 @@ for the content you can use with a [kustomize](https://kustomize.io/). - [deployment-1.yaml](https://github.com/nvtkaszpir/prusa-connect-camera-script/blob/master/k8s/deployment-1.yaml) is an example to fetch image from a stream using ffmpeg and with custom - prusa-connect-camera.sh for easier development/iteration + prusa-connect-camera.sh for easier development/iteration. + This is also preferred option when you are not using cameras that are directly + attached to the hosts, but rely on using ffmpeg to fetch images from remote + streams or static images via curl. - [deployment-2.yaml](https://github.com/nvtkaszpir/prusa-connect-camera-script/blob/master/k8s/deployment-2.yaml) is an example how to run it on Raspberry Pi with USB camera using default parameters. You want to change `.spec.nodeName` and volumes to point to desired camera. +- [daemonset.yaml](https://github.com/nvtkaszpir/prusa-connect-camera-script/blob/master/k8s/daemonset.yaml) + is an example how to run it on Raspberry Pi with USB camera using default parameters. + You want to change `.spec.nodeName` and volumes to point to desired camera. + The difference between the DaemonSet and Deployment is that with the Deployment + kubernetes will try to spawn new pods even if node is not available. + DaemonSet it is better when you have to use directly attached devices to the hosts. + ## More copies If you want to add more cameras then you should: diff --git a/k8s/daemonset.yaml b/k8s/daemonset.yaml new file mode 100644 index 0000000..ee270f0 --- /dev/null +++ b/k8s/daemonset.yaml @@ -0,0 +1,89 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet + +metadata: + name: cam-2 + labels: + app.kubernetes.io/name: cam-2 +spec: + revisionHistoryLimit: 3 + + updateStrategy: + type: RollingUpdate + + selector: + matchLabels: + app.kubernetes.io/name: cam-2 + + template: + metadata: + labels: + app.kubernetes.io/name: cam-2 + + spec: + nodeName: hormex # change this to the desired host with given hardware + automountServiceAccountToken: false + enableServiceLinks: false + containers: + - name: prusa-connect-script + tty: true # get that logs flowing to stdout/stderr + envFrom: + - secretRef: + name: cam-2 + image: quay.io/kaszpir/prusa-connect-script:latest + imagePullPolicy: IfNotPresent + lifecycle: + preStop: + exec: + command: ["/bin/sh","-c","echo graceful-shutdown-start;sleep 2;echo graceful-shutdown-end"] # wait for inflight requests to finish + livenessProbe: + exec: + command: + - bash + - -c + - test $(find /dev/shm/ -mmin -1 | wc -l) -gt "0" + initialDelaySeconds: 5 + periodSeconds: 15 + + securityContext: + # allowPrivilegeEscalation: false + privileged: true + readOnlyRootFilesystem: true + runAsNonRoot: true + runAsUser: 1000 + capabilities: + drop: + - ALL + # add: + # - NET_RAW # needed for ping if not using + + resources: + requests: + cpu: "0.1" + memory: "32Mi" + limits: + cpu: "1.0" + memory: "128Mi" + + volumeMounts: + - mountPath: /dev/shm + name: dev-shm + - mountPath: /dev/video999 # must be the same as in `volumes` section and in cam.env + name: dev-video + # securityContext: + # runAsUser: 1000 + # # runAsGroup: video + # # fsGroup: 2000 + tolerations: + - key: "rpi" + operator: "Exists" + effect: "NoSchedule" + terminationGracePeriodSeconds: 5 + volumes: + - name: dev-shm + emptyDir: + medium: Memory + - name: dev-video + hostPath: + path: /dev/video1 # change this to the device on the host diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml index 6f9f91e..610285f 100644 --- a/k8s/kustomization.yaml +++ b/k8s/kustomization.yaml @@ -8,6 +8,7 @@ resources: - deployment-1.yaml # - deployment-2.yaml + - daemonset.yaml secretGenerator: - name: cam-1