Skip to content

Commit

Permalink
Kubernetes add DaemonSet for direct cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
nvtkaszpir committed Jul 13, 2024
1 parent f07ed5c commit 7aae43c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/service.kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
89 changes: 89 additions & 0 deletions k8s/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions k8s/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ resources:

- deployment-1.yaml
# - deployment-2.yaml
- daemonset.yaml

secretGenerator:
- name: cam-1
Expand Down

0 comments on commit 7aae43c

Please sign in to comment.