Skip to content

Latest commit

 

History

History
221 lines (153 loc) · 4.86 KB

README.md

File metadata and controls

221 lines (153 loc) · 4.86 KB

mnist-openfaas-example

Environment Install

Docker

Docker Official Documentation

Install Docker Engine on Ubuntu

  • Step 1: Set up Docker's apt repository.
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
  • Step 2: Install the Docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

OpenFaaS

See openfaas-example README.md

OpenFaaS Command Line Tool (faas-cli)

  • macOS
    • brew install faas-cli
  • Ubuntu
    • Root user
      • curl -sSL https://cli.openfaas.com | sudo -E sh
    • Non root user
      • curl -sSL https://cli.openfaas.com | sh

Kubernetes

  • Step 1: Create Kubernetes Namespace

    kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml
  • Step 2: Helm charts

    helm repo add openfaas https://openfaas.github.io/faas-netes/
    helm repo update
    helm upgrade openfaas --install openfaas/openfaas --namespace openfaas
  • (Optional) Step 3: Expose OpenFaaS Gateway Service to LoadBalancer

    kubectl patch svc gateway-external -n openfaas -p '{"spec":{"type": "LoadBalancer"}}'
  • Step 4: Get OpenFaaS admin Password

    PASSWORD=$(kubectl -n openfaas get secret basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode) && \
    echo "OpenFaaS admin password: $PASSWORD"
  • Step 5: Login OpenFaaS WebUI via credential

    # Default gateway endpoint is http://127.0.0.1:8080
    faas-cli login -u admin -p $PASSWORD
    
    # Specify gateway endpoint, for example http://10.0.0.156:31112
    faas-cli login -u admin -p $PASSWORD -g http://10.0.0.156:31112

MinIO Server

MinIO Official Documentation

Install

  • Ubuntu

    wget https://dl.min.io/server/minio/release/linux-amd64/archive/minio_20240305044844.0.0_amd64.deb -O minio.deb
    sudo dpkg -i minio.deb

Launch

mkdir ~/minio
minio server ~/minio --console-address :9001

Connect browser to MinIO Server

MinIO WebUI default account: minioadmin MinIO WebUI default password: minioadmin

http://<HOST_IP>:9001

# Example
# http://10.0.0.156:9001

MinIO Client

MinIO Official Documentation

Install

wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
sudo mv mc /usr/local/bin/mc

Config

mc alias set <ALIAS_NAME> http://<HOST_IP>:9000 <ACCESS_KEY> <SECRET_KEY> 
mc admin info <ALIAS_NAME>

# Example
# mc alias set local http://10.0.0.156:9000 minioadmin minioadmin
# mc admin info local
Python Client API

MinIO Python Client API Official Documentation

from minio import Minio

def connect_minio():
    """Connect to MinIO Server"""

    MINIO_API_ENDPOINT = os.environ["minio_api_endpoint"]
    MINIO_ACCESS_KEY = os.environ["minio_access_key"]
    MINIO_SECRET_KEY = os.environ["minio_secret_key"]

    return Minio(
        MINIO_API_ENDPOINT,
        access_key=MINIO_ACCESS_KEY,
        secret_key=MINIO_SECRET_KEY,
        secure=False # Disable HTTPS
    )

Build, Push, Deploy, Remove OpenFaaS Functions

One-key to build, push, deploy (Recommand)

# Default architecture is amd64
make faas-up

# Specify architecture, for example arm64
make faas-up ARCH=arm64

Manual

  • Build

    # Default architecture is amd64
    make faas-build
    
    # Specify architecture, for example arm64
    make faas-build ARCH=arm64
  • Push

    # Default architecture is amd64
    make faas-push
    
    # Specify architecture, for example arm64
    make faas-push ARCH=arm64
  • Deploy

    # Default architecture is amd64
    make faas-deploy
    
    # Specify architecture, for example arm64
    make faas-deploy ARCH=arm64
  • Remove

    # Default architecture is amd64
    make faas-remove
    
    # Specify architecture, for example arm64
    make faas-remove ARCH=arm64

References

  1. https://neptune.ai/blog/saving-trained-model-in-python