OpenFaaS を Docker Swarm 上にインストールする

OpenFaas を Docker Swarm 環境で起動した時のメモ。

  1. GitHub から OpenFaas をクローンする

    1
    2
    3
    4
    5
    6
    7
    8
    9
    $ git clone https://github.com/openfaas/faas
    Cloning into 'faas'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 20383 (delta 0), reused 0 (delta 0), pack-reused 20380
    Receiving objects: 100% (20383/20383), 23.62 MiB | 966.00 KiB/s, done.
    Resolving deltas: 100% (9028/9028), done.
    Checking connectivity... done.
  2. ディレクトリーを移動する

    1
    $ cd faas/
  3. デプロイする

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    $ ./deploy_stack.sh
    Attempting to create credentials for gateway..
    36rt2h6hforcr0h82qtgshjqz
    oq2m7gjfbmvb1u7mb7rg0s3uy
    [Credentials]
    username: admin
    password: 8f35a7ff60f2749d1b4014bbce73cdb2df555cec4e78d0bf983cd6cc6e090680
    echo -n 8f35a7ff60f2749d1b4014bbce73cdb2df555cec4e78d0bf983cd6cc6e090680 | faas-cli login --username=admin --password-stdin
    Enabling basic authentication for gateway..

    Deploying OpenFaaS core services
    Creating network func_functions
    Creating config func_prometheus_rules
    Creating config func_alertmanager_config
    Creating config func_prometheus_config
    Creating service func_prometheus
    Creating service func_alertmanager
    Creating service func_gateway
    Creating service func_basic-auth-plugin
    Creating service func_faas-swarm
    Creating service func_nats
    Creating service func_queue-worker
    `
  4. Docker Swarm 上にサービスが起動していることを確認する

    1
    2
    3
    4
    5
    6
    7
    8
    9
    $ sudo docker service ls
    ID NAME MODE REPLICAS IMAGE PORTS
    lcna1kfs15jp func_alertmanager replicated 1/1 prom/alertmanager:v0.18.0
    zeclxis2l8cj func_basic-auth-plugin replicated 0/1 openfaas/basic-auth-plugin:0.18.18
    e2wizc9oj3g3 func_faas-swarm replicated 0/1 openfaas/faas-swarm:0.9.0
    mqq8bx2wgbg8 func_gateway replicated 0/1 openfaas/gateway:0.18.18 *:8080->8080/tcp
    skbr4l6exacv func_nats replicated 0/1 nats-streaming:0.17.0
    l1az9pin6wl7 func_prometheus replicated 0/1 prom/prometheus:v2.11.0 *:9090->9090/tcp
    8s57frhgyvry func_queue-worker replicated 0/1 openfaas/queue-worker:0.11.2
  5. faas-cli をインストールする

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    $ curl -sL cli.openfaas.com | sh
    Finding latest version from GitHub
    0.12.13
    Downloading package https://github.com/openfaas/faas-cli/releases/download/0.12.13/faas-cli as /home/user/faas/faas-cli
    Download complete.

    ============================================================
    The script was run as a user who is unable to write
    to /usr/local/bin. To complete the installation the
    following commands may need to be run manually.
    ============================================================

    sudo cp faas-cli /usr/local/bin/faas-cli
    sudo ln -sf /usr/local/bin/faas-cli /usr/local/bin/faas
  6. 実行結果の最後に表示されているコマンドを実行する

    1
    2
    $ sudo cp faas-cli /usr/local/bin/faas-cli
    $ sudo ln -sf /usr/local/bin/faas-cli /usr/local/bin/faas
  7. faas-cli コマンドがインストールされたことを確認する

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    $ faas-cli --help

    Manage your OpenFaaS functions from the command line

    Usage:
    faas-cli [flags]
    faas-cli [command]

    Available Commands:
    auth Obtain a token for your OpenFaaS gateway
    build Builds OpenFaaS function containers
    cloud OpenFaaS Cloud commands
    completion Generates shell auto completion
    deploy Deploy OpenFaaS functions
    describe Describe an OpenFaaS function
    generate Generate Kubernetes CRD YAML file
    help Help about any command
    invoke Invoke an OpenFaaS function
    list List OpenFaaS functions
    login Log in to OpenFaaS gateway
    logout Log out from OpenFaaS gateway
    logs Tail logs from your functions
    namespaces List OpenFaaS namespaces
    new Create a new template in the current folder with the name given as name
    push Push OpenFaaS functions to remote registry (Docker Hub)
    remove Remove deployed OpenFaaS functions
    secret OpenFaaS secret commands
    store OpenFaaS store commands
    template OpenFaaS template store and pull commands
    up Builds, pushes and deploys OpenFaaS function containers
    version Display the clients version information

    Flags:
    --filter string Wildcard to match with function names in YAML file
    -h, --help help for faas-cli
    --regex string Regex to match with function names in YAML file
    -f, --yaml string Path to YAML file describing function(s)

    Use "faas-cli [command] --help" for more information about a command.
    $ faas-cli version
    ___ _____ ____
    / _ \ _ __ ___ _ __ | ___|_ _ __ _/ ___|
    | | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
    | |_| | |_) | __/ | | | _| (_| | (_| |___) |
    \___/| .__/ \___|_| |_|_| \__,_|\__,_|____/
    |_|

    CLI:
    commit: 035617290e62b1cd40cd767c6f55d7f72002582d
    version: 0.12.13
    `
  8. OpenFaas のゲートウェイにログインする

    1
    2
    3
    4
    $  echo -n 8f35a7ff60f2749d1b4014bbce73cdb2df555cec4e78d0bf983cd6cc6e090680 | faas-cli login --username=admin --password-stdin
    Calling the OpenFaaS server to validate the credentials...
    WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
    credentials saved for admin http://127.0.0.1:8080
  9. ブラウザーからアクセスする