Kubeless

安装非常简单,只是别用 microk8s 有一个服务启动不起来,rke2 实测没有问题

export RELEASE=$(curl -s https://api.github.com/repos/kubeless/kubeless/releases/latest | grep tag_name | cut -d '"' -f 4)
kubectl create ns kubeless
kubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-$RELEASE.yaml

kubectl get pods -n kubeless

export OS=$(uname -s| tr '[:upper:]' '[:lower:]')
curl -OL https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless_$OS-amd64.zip && \
  unzip kubeless_$OS-amd64.zip && \
  sudo mv bundles/kubeless_$OS-amd64/kubeless /usr/local/bin/

查看支持的 runtime

root@ubuntu:~# kubeless get-server-config
INFO[0000] Current Server Config:                       
INFO[0000] Supported Runtimes are: ballerina0.981.0, dotnetcore2.0, dotnetcore2.1, dotnetcore2.2, dotnetcore3.1, go1.13, go1.14, java1.8, java11, nodejs10, nodejs12, nodejs14, php7.2, php7.3, php7.4, python3.6, python3.7, python3.8, ruby2.3, ruby2.4, ruby2.5, ruby2.6, jvm1.8, nodejs_distroless8, nodejsCE8, vertx1.8 
root@ubuntu:~# 

我们创建一个 test.py

def hello(event, context):
  print(event)
  return event['data']

然后通过这个文件创建一个 function

kubeless function deploy hello --runtime python3.7 \
                                --from-file test.py \
                                --handler test.hello

这里需要下载一个镜像,所以需要等待,不要直接启动

可以添加 -n Namespace

kubeless function deploy hello --runtime python3.7 \
                                --from-file test.py \
                                --handler test.hello \
                                -n lizhe

安装 UI

kubectl create -f https://raw.githubusercontent.com/kubeless/kubeless-ui/master/k8s.yaml

kubectl proxy -p 8080
curl -L --data '{"Another": "Echo"}' \
  --header "Content-Type:application/json" \
  localhost:8080/api/v1/namespaces/default/services/hello:http-function-port/proxy/

Send a Message