0
0

OpenFaas on ラズパイ5 kubernetes デプロイができない

Posted at

構築したはいいものの、デプロイで失敗続きだったのでそのログ

前提

  • ラズパイ5、Docker利用
  • OpenFaaS環境構築済み
  • faas-cliインストール、ログイン済み

まず通常手順でやってみる

python3のテンプレートを利用

$ faas-cli new my-function --lang python3
$ ls
my-function  my-function.yml  template

ビルドでエラー発生

ビルドは

のとおり、(ymlファイルの指定も必要)

$ faas-cli up -f my-function.yml

しかしエラー発生

[0] > Building my-function.
Building: my-function:latest with python3 template. Please wait..
Sending build context to Docker daemon  9.216kB
Step 1/32 : ARG PYTHON_VERSION=3
Step 2/32 : FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 as watchdog
 ---> 13f4a510436c
Step 3/32 : FROM --platform=${TARGETPLATFORM:-linux/amd64} python:${PYTHON_VERSION}-alpine
 ---> 9ad3ec94c61c
Step 4/32 : ARG TARGETPLATFORM
 ---> Using cache
 ---> 1955abe6b0b9
Step 5/32 : ARG BUILDPLATFORM
 ---> Using cache
 ---> cf53c7e035ae
Step 6/32 : ARG ADDITIONAL_PACKAGE
 ---> Using cache
 ---> 8f9de6a4ce3e
Step 7/32 : COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
 ---> Using cache
 ---> cb6e5ad68f6a
Step 8/32 : RUN chmod +x /usr/bin/fwatchdog
 ---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
 ---> Running in 53ffaf3404de
exec /bin/sh: exec format error
The command '/bin/sh -c chmod +x /usr/bin/fwatchdog' returned a non-zero code: 1
[0] < Building my-function done in 0.55s.
[0] Worker done.

Total build time: 0.55s
Errors received during build:
- [my-function] received non-zero exit code from build, error: The command '/bin/sh -c chmod +x /usr/bin/fwatchdog' returned a non-zero code: 1

エラーを眺めてみる

カレントディレクトリにbuild/my-functionが作成されている。
やろうとしていること自体はこのDockerfileをみればわかる
失敗しているのは

RUN chmod +x /usr/bin/fwatchdog

の部分だが、そもそも

FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 as watchdog

でamd64を選択していること自体が間違いのように感じる。

ビルドは成功!

docker buildxを有効にして、かつplatformを指定しながらbuildする

$ docker buildx version
github.com/docker/buildx v0.15.1 1c1dbb2

$ DOCKER_BUILDKIT=1 faas-cli build -f my-function.yml --no-cache --build-arg platform=linux/arm64/v8

しかし今度はpushでエラー

$ faas-cli push -f my-function.yml 

Unable to push one or more of your functions to Docker Hub:
- my-function

You must provide a username or registry prefix to the Function's image such as user1/function1

push先はDocker Hubである必要がありそうです。

一旦お片付け

ビルドからやり直すので、今作ったイメージを削除する

$ docker images
REPOSITORY                          TAG                    IMAGE ID       CREATED         SIZE
my-function                         latest                 61dc3499e243   9 minutes ago   79.7MB
$ docker rmi my-function

push先をDocker Hubにする

Docker Hubアカウント作成

Googleログイン等もあるが、結局コマンドラインでのログインでパスワード必要になるのでパスワードリセットする羽目になる。

Dockerログイン

コマンドラインでログイン

$ docker login -u [DockerUserName] --password ********

Docker Hubアカウントがpush先になるように、イメージ名の頭にユーザー名を入れる

my-function.yml
image: [DockerUserName]/my-function:latest

ビルドからやり直し

$ DOCKER_BUILDKIT=1 faas-cli build -f my-function.yml --no-cache --build-arg platform=linux/arm64/v8

$ faas-cli push -f my-function.yml

成功!
このままデプロイまでいけるか...?

デプロイ成功

いけました。

$ faas-cli deploy -f my-function.yml 
Deploying: my-function.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/my-function

$ faas-cli list
Function                        Invocations     Replicas
my-function                     0               1

upもビルドと同じように使えました。

DOCKER_BUILDKIT=1 faas-cli up -f my-function.yml --no-cache --build-arg platform=linux/arm64/v8

まとめ

  • デフォルトの状態では使用するDockerコンテナイメージがx86用なので、ARMを積んだラズパイで実行するときはbuildxでARM向けにクロスコンパイルしてビルドする必要がある
  • Docker Hubにイメージをpushするので、アカウントの作成が必要
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0