LoginSignup
6
7

More than 3 years have passed since last update.

n8nをOpenShiftにデプロイしてみよう

Posted at

はじめに

n8n(nodemation)は、公式ページにもある通り、Zapierの代わりとなるオープンソースのワークフロー自動化ツールです。
image.png

以下youtubeにデモ動画がある通り、各種ツールの連携を比較的容易に出来るようになります。
youtube_IMAGE

構成

OpenShift on IBM Cloud上のアプリケーションとしてn8nをデプロイします。
OKDやminishiftでも同様の手順でデプロイ出来るかと思います。

手順

n8nアプリケーションのデプロイ

n8nをOpenshift上で普通に動かそうとすると、permissionが足りないためPodが立ち上がりません。

$ oc new-app n8nio/n8n
--> Found Docker image bec8c96 (24 hours old) from Docker Hub for "n8nio/n8n"

    * An image stream tag will be created as "n8n:latest" that will track this image
    * This image will be deployed in deployment config "n8n"
    * The image does not expose any ports - if you want to load balance or send traffic to this component
      you will need to create a service with 'expose dc/n8n --port=[port]' later
    * WARNING: Image "n8nio/n8n" runs as the 'root' user which may not be permitted by your cluster administrator

--> Creating resources ...
    imagestream.image.openshift.io "n8n" created
    deploymentconfig.apps.openshift.io "n8n" created
--> Success
    Run 'oc status' to view your app.

### Successしたように見えて、、、CrashLoopBackOffとなっています。
$ oc get pod
NAME                 READY     STATUS             RESTARTS   AGE
n8n-1-flprw          0/1       CrashLoopBackOff   6          6m

イベントログを確認すると、

UserSettings got generated and saved to: /.n8n/config
(node:1) UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, mkdir '/.n8n'
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1) UnhandledPromiseRejectionWarning: Error: There was an error: EACCES: permission denied, mkdir '/.n8n'
    at Object.error (/usr/local/lib/node_modules/n8n/node_modules/@oclif/errors/lib/index.js:22:17)
    at Start.error (/usr/local/lib/node_modules/n8n/node_modules/@oclif/command/lib/command.js:57:23)
    at /usr/local/lib/node_modules/n8n/dist/commands/start.js:112:22
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

OpneShiftはルート権限でのコンテナ操作を禁止しており、n8nはそれに引っかかってしまいます。

そのため、Security Context Constraintsとそれを割り当てたService Accountを用いて動かします。

まず以下コマンドでService Accountを作成します。

$ oc create sa with-anyuid

次にService Accountに、「anyuid」を付与しましょう。

$ oc adm policy add-scc-to-user anyuid -z with-anyuid --as system:admin
scc "anyuid" added to: ["system:serviceaccount:sandbox:with-anyuid"]

このService Accountを使って、Security Context Constraintsをコンテナに適用してみます。

先程起動に失敗したアプリケーションに対して以下コマンドでService Accountを適用します。

oc patch dc/n8n --patch '{"spec":{"template":{"spec":{"serviceAccountName": "with-anyuid"}}}}'

これで正しく起動するはずです。

Webブラウザ経由でアクセスするためのルート作成

アプリケーションが起動してきたら外部アクセス出来るように、以下コマンドでServiceとRouteを作成します。

$ oc expose dc/n8n --name=n8n --port=5678
service/n8n exposed

$ oc expose service n8n
route.route.openshift.io/n8n exposed

作成できたら、以下コマンドでアクセス用URLが確認できます。

$ oc get route
NAME               HOST/PORT                                                                                                            PATH      SERVICES           PORT               TERMINATION   WILDCARD
n8n                n8n-default.testcluster-xxxxxxxxxyyyyyyyyyyzzzzzzzzzzz-0001.jp-tok.containers.appdomain.cloud                                  n8n                5678                             None

上記URLにhttpアクセスするとn8nのコンソール画面が表示されます。
http://n8n-default.testcluster-xxxxxxxxxyyyyyyyyyyzzzzzzzzzzz-0001.jp-tok.containers.appdomain.cloud

image.png

まだまだ連携出来るツールは少ないので、今後に期待です!

参考情報

n8n.ioをIKS(IBM Cloud Kubernetes Service)で動かすまで

6
7
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
6
7