rpi-rgb-led-matrix icon indicating copy to clipboard operation
rpi-rgb-led-matrix copied to clipboard

Unable to CreateFrameCanvas kubernetes

Open Apollorion opened this issue 3 years ago • 2 comments

I am able to run this project directly on a raspberry pi, but I would prefer to run it in a docker container in kubernetes (microk8s, ubuntu 21.04, using the same raspberry pi as mentioned before just in a container this time). Is this even possible for one?

This is my dockerfile:

FROM ubuntu:20.04

RUN apt-get update && apt-get install -y git make build-essential python3 python3-pip python3-distutils python3-dev \
    && $(which python3) -m pip install Pillow \
    && git clone https://github.com/hzeller/rpi-rgb-led-matrix.git \
    && cd rpi-rgb-led-matrix \
    && make build-python PYTHON=$(which python3) \
    && make install-python PYTHON=$(which python3) \
    && mkdir /app

COPY . /app

ENTRYPOINT ["python3", "-u", "/app/run_text.py"]

It builds fine and seems to run, until I call matrix.CreateFrameCanvas()

matrix is setup as such:

options = RGBMatrixOptions()
options.hardware_mapping = "adafruit-hat"
options.rows = 16
options.cols = 32
options.chain_length = 3
options.parallel = 1
options.row_address_type = 0
options.multiplexing = 4
options.pwm_bits = 11
options.brightness = 30
options.pwm_lsb_nanoseconds = 130
options.led_rgb_sequence = "RGB"
options.pixel_mapper_config = ""
options.panel_type = ""
options.drop_privileges=False

matrix = RGBMatrix(options = options)

The kubernetes deployment is:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ledsign
  namespace: ledsign
spec:
  selector:
    matchLabels:
      app: ledsign
  replicas: 1
  template:
    metadata:
      labels:
        app: ledsign
    spec:
      nodeSelector:
        kubernetes.io/hostname: led-sign
      imagePullSecrets:
        - name: ghcr-image-pull-secret
      containers:
        - name: ledsign
          image: ghcr.io/apollorion/led-project:aarch64
          imagePullPolicy: Always
          securityContext:
#            capabilities:
#              add: [ "CAP_SYS_ADMIN" ]
            allowPrivilegeEscalation: false
            runAsUser: 0
          volumeMounts:
            - mountPath: /dev/gpiomem
              name: gpiomem
            - mountPath: /dev/mem
              name: mem
      volumes:
        - name: gpiomem
          hostPath:
            path: /dev/gpiomem
            type: CharDevice
        - name: mem
          hostPath:
            path: /dev/mem
            type: CharDevice

I dont get a stack trace or anything, once it hits that matrix.CreateFrameCanvas() my container just stops. Is there an environment variable or something I can add to get some debug information on what is happening?

Apollorion avatar Sep 22 '22 02:09 Apollorion

I was able to get this working by setting privileged: true on the container.

FWIW, it may be useful to publish this container for other folks to use as a layer to build upon. It works perfectly in Kubernetes for me, and containerizing this library would make implementation super easy for additional folks IMO.

Apollorion avatar Sep 22 '22 14:09 Apollorion

I also now have a full working example here, if anyone is interested: https://github.com/Apollorion/led-project

Apollorion avatar Sep 22 '22 14:09 Apollorion