Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K8s deployment files for WAMR #736

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions .github/workflows/azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ name: "Azure Integration Tests"
# These tests provision resources on Faasm's Azure subscription to run
# integration tests on a production environment. To limit the cost of running
# them, we only trigger them on workflow dispatch. In order to run them, you
# need to navigate to the Actions tab on GitHub, and click the run button
on: workflow_dispatch
# need to navigate to the Actions tab on GitHub, and click the run button.
# Additionally, we also run them when we change the deployment files, to check
# that we don't break anything
on:
workflow_dispatch:
push:
branches:
- "main"
paths:
- "deploy/**yml"

defaults:
run:
Expand All @@ -13,8 +21,6 @@ defaults:
jobs:
aks:
runs-on: self-hosted
env:
CLUSTER_NAME_BASE: gha-cluster
strategy:
fail-fast: true
# Running two Kubernetes clusters side-by-side from the same user in the
Expand All @@ -25,7 +31,10 @@ jobs:
# run one after the other, so we don't implement the fix.
max-parallel: 1
matrix:
sgx: [True, False]
wasm_vm: [wamr, wavm, sgx]
env:
CLUSTER_NAME_BASE: gha-cluster
WASM_VM: ${{ matrix.wasm_vm }}
steps:
- name: "Check out the experiment-base code"
uses: actions/checkout@v3
Expand All @@ -34,14 +43,14 @@ jobs:
path: experiment-base
- name: "Create a unique cluster name"
run: |
[[ "${{ matrix.sgx }}" == "true" ]] && SUFFIX_SGX="-sgx" || SUFFIX_SGX=""
echo "CLUSTER_NAME=${CLUSTER_NAME_BASE}${SUFFIX_SGX}-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}" >> $GITHUB_ENV
echo "CLUSTER_NAME=${CLUSTER_NAME_BASE}-${{ matrix.wasm_vm }}-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}" >> $GITHUB_ENV
- name: "Install kubectl"
run: ./bin/inv_wrapper.sh k8s.install-kubectl
working-directory: ${{ github.workspace }}/experiment-base
- name: "Start a managed k8s cluster on Azure's Kubernetes Service"
run: |
./bin/inv_wrapper.sh cluster.provision --name ${{ env.CLUSTER_NAME }} --vm Standard_DC4s_v3 --nodes 4 --location eastus2 --sgx ${{ matrix.sgx }}
[[ "${{ matrix.wasm_vm }}" == "sgx" ]] && SUFFIX_SGX="True" || SUFFIX_SGX="False"
./bin/inv_wrapper.sh cluster.provision --name ${{ env.CLUSTER_NAME }} --vm Standard_DC4s_v3 --nodes 4 --location eastus2 --sgx ${SUFFIX_SGX}
./bin/inv_wrapper.sh cluster.credentials --name ${{ env.CLUSTER_NAME }}
working-directory: ${{ github.workspace }}/experiment-base
- name: "Check out faasm code"
Expand All @@ -50,7 +59,7 @@ jobs:
submodules: true
path: faasm
- name: "Deploy Faasm on k8s cluster"
run: ./bin/inv_wrapper.sh k8s.deploy --workers=4 --sgx ${{ matrix.sgx }}
run: ./bin/inv_wrapper.sh k8s.deploy --workers=4
working-directory: ${{ github.workspace }}/faasm
- name: "Build, upload and run a simple CPP function"
run: docker compose -f docker-compose-k8s.yml run -T cpp-cli ./bin/inv_wrapper.sh func demo hello func.upload demo hello func.invoke demo hello
Expand Down
30 changes: 30 additions & 0 deletions deploy/k8s-wamr/upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

apiVersion: v1
kind: Pod
metadata:
name: upload
namespace: faasm
labels:
app: faasm
role: upload
spec:
containers:
- name: upload
image: faasm.azurecr.io/upload:0.9.5
ports:
- containerPort: 8002
- containerPort: 5000
env:
- name: REDIS_STATE_HOST
value: "redis-state"
- name: REDIS_QUEUE_HOST
value: "redis-queue"
- name: LOG_LEVEL
value: "info"
- name: LD_LIBRARY_PATH
value: "/build/faasm/third-party/lib:/usr/local/lib"
- name: PYTHON_CODEGEN
value: "off"
- name: WASM_VM
value: "wamr"
64 changes: 64 additions & 0 deletions deploy/k8s-wamr/worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---

apiVersion: apps/v1
kind: Deployment
metadata:
name: faasm-worker
namespace: faasm
labels:
app: faasm
spec:
selector:
matchLabels:
run: faasm-worker
replicas: 2
template:
metadata:
labels:
run: faasm-worker
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: run
operator: In
values:
- faasm-worker
topologyKey: kubernetes.io/hostname
weight: 100

containers:
- image: faasm.azurecr.io/worker:0.9.5
name: faasm-worker
ports:
- containerPort: 8080
env:
- name: REDIS_STATE_HOST
value: "redis-state"
- name: REDIS_QUEUE_HOST
value: "redis-queue"
- name: LOG_LEVEL
value: "info"
- name: CAPTURE_STDOUT
value: "on"
- name: CGROUP_MODE
value: "off"
- name: NETNS_MODE
value: "off"
- name: MAX_NET_NAMESPACES
value: "100"
- name: PYTHON_PRELOAD
value: "off"
- name: PYTHON_CODEGEN
value: "off"
- name: BOUND_TIMEOUT
value: "600000"
- name: GLOBAL_MESSAGE_TIMEOUT
value: "700000"
- name: ENDPOINT_INTERFACE
value: "eth0"
- name: WASM_VM
value: "wamr"
51 changes: 31 additions & 20 deletions faasmcli/faasmcli/tasks/k8s.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from os import makedirs, listdir
from os import environ, listdir, makedirs
from os.path import join
from subprocess import run, PIPE
from time import sleep
Expand All @@ -17,7 +17,8 @@

K8S_COMMON_DIR = join(PROJ_ROOT, "deploy", "k8s-common")
K8S_SGX_DIR = join(PROJ_ROOT, "deploy", "k8s-sgx")
K8S_DIR = join(PROJ_ROOT, "deploy", "k8s")
K8S_WAVM_DIR = join(PROJ_ROOT, "deploy", "k8s")
K8S_WAMR_DIR = join(PROJ_ROOT, "deploy", "k8s-wamr")
NAMESPACE_FILE = join(K8S_COMMON_DIR, "namespace.yml")


Expand Down Expand Up @@ -61,16 +62,19 @@ def _get_faasm_worker_pods(label):
return names, ips


@task(optional=["sgx"])
def deploy(ctx, workers, sgx=False):
@task
def deploy(ctx, workers):
"""
Deploy Faasm to a k8s cluster
"""
# We can disable SGX by either not setting the flag (i.e. no --sgx) or by
# setting the flag with value "False" (i.e. --sgx False). Supporting this
# makes it possible to enable SGX conditionally from Github Actions
sgx = sgx and sgx.lower() != "false"
_deploy_faasm_services(int(workers), sgx)

# Pick the right WASM VM
if "WASM_VM" in environ:
wasm_vm = environ["WASM_VM"]
else:
wasm_vm = "wavm"

_deploy_faasm_services(int(workers), wasm_vm)

ini_file(ctx)

Expand Down Expand Up @@ -118,7 +122,7 @@ def wait_for_faasm_lb(service_name):
sleep(5)


def _deploy_faasm_services(worker_replicas, sgx=False):
def _deploy_faasm_services(worker_replicas, wasm_vm):
# Set up the namespace first
run(
"kubectl apply -f {}".format(NAMESPACE_FILE),
Expand All @@ -134,16 +138,18 @@ def _deploy_faasm_services(worker_replicas, sgx=False):
]

# Then add the deployment specific files
if sgx:
k8s_files += [
join(K8S_SGX_DIR, f)
for f in listdir(K8S_SGX_DIR)
if f.endswith(".yml")
]
if wasm_vm == "sgx":
k8s_dir = K8S_SGX_DIR
elif wasm_vm == "wamr":
k8s_dir = K8S_WAMR_DIR
elif wasm_vm == "wavm":
k8s_dir = K8S_WAVM_DIR
else:
k8s_files += [
join(K8S_DIR, f) for f in listdir(K8S_DIR) if f.endswith(".yml")
]
print("Unrecognised WASM VM: {}".format(wasm_vm))
raise RuntimeError("Unrecognised WASM VM")
k8s_files += [
join(k8s_dir, f) for f in listdir(k8s_dir) if f.endswith(".yml")
]

# Apply all the files
print("Applying k8s files: {}".format(k8s_files))
Expand Down Expand Up @@ -181,7 +187,12 @@ def delete(ctx, local=False, sgx=False):
Remove Faasm's k8s cluster
"""
# Delete the rest
for dir_to_delete in [K8S_COMMON_DIR, K8S_DIR, K8S_SGX_DIR]:
for dir_to_delete in [
K8S_COMMON_DIR,
K8S_WAVM_DIR,
K8S_WAMR_DIR,
K8S_SGX_DIR,
]:
cmd = "kubectl delete --all -f {}".format(dir_to_delete)
print(cmd)
run(cmd, shell=True, check=True)
Expand Down