0
1

OpenFaaSをラズパイ5 kubernetes上で構築する

Last updated at Posted at 2024-07-17

前提

  • ラズパイ5、Raspbian OS
  • Dockerをすでにがしがし使っているので、その環境を残したうえで、K3S上に構築済み

参考

OpenFaas構築

helmをインストールしておく。

$ curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
$ helm version
version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}

faas-netesをクローン(実際使うのはinstall.shだけっぽいですが...)

$ curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
$ git clone https://github.com/openfaas/faas-netes
$ cd faas-netes
$ ./install.sh

しかしそのままだと失敗

$ ./install.sh 
Installing with helm 👑
"openfaas" has been added to your repositories
namespace/openfaas created
namespace/openfaas-fn created
secret/basic-auth created
Installing chart 🍻
Error: Kubernetes cluster unreachable: Get "http://localhost:8080/version": dial tcp [::1]:8080: connect: connection refused

「HelmからKubernetesクラスタにアクセスできない旨のエラーが出ることがある。」だそうです。

成功パターン

$ kubectl config view --raw > ~/.kube/config
$ ./install.sh

成功すると、サービスが立ち上がる

$ kubectl get namespaces
NAME              STATUS   AGE
default           Active   4d4h
kube-node-lease   Active   4d4h
kube-public       Active   4d4h
kube-system       Active   4d4h
openfaas          Active   11m
openfaas-fn       Active   11m

$ kubectl get svc -n openfaas
NAME               TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
alertmanager       ClusterIP      10.43.35.45     <none>        9093/TCP         11m
gateway            ClusterIP      10.43.177.176   <none>        8080/TCP         11m
gateway-external   LoadBalancer   10.43.128.54    192.168.0.9   8080:31213/TCP   11m
nats               ClusterIP      10.43.177.189   <none>        4222/TCP         11m
prometheus         ClusterIP      10.43.51.225    <none>        9090/TCP         11m

http://localhost:8080 (gateway)にアクセス。
ユーザーはadmin、パスワードは

$ kubectl get secret basic-auth -n openfaas -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo

で取得可能
image.png

faas-cliインストール

curl -sL https://cli.openfaas.com | sudo sh

faas-cliログイン

$ echo $(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo) | faas-cli login --username admin --password-stdin

関数デプロイ

続きはこちら

後片付け

つかわなくなったら

openfaasとopenfaas-fnという2つのnamespaceがあるので、それを削除

$ kubectl get namespaces
NAME              STATUS   AGE
default           Active   4d4h
kube-node-lease   Active   4d4h
kube-public       Active   4d4h
kube-system       Active   4d4h
openfaas          Active   4d3h
openfaas-fn       Active   4d3h

$ kubectl delete namespace openfaas openfaas-fn

不明点

  • gatewayのポート番号変更方法
    8080番はよく使うので、できれば他のポートを指定したいが、faas-netes内で"8080"で検索するとかなりの数がヒットする。

  • gatewayとgateway-externalのどちらを使うべきか
    faas-cliのログインはgatewayでよいと思う。
    むしろfaas-cliのgatewayのデフォルト設定がlocalhost:8080なので、変更しようとすると逆にめんどくさそう。
    外部からのアクセスについても、プロキシ設定でどちらのポートに繋ぐかの違いだけに見えますが、何か意味があるのでしょうか。
0
1
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
1