fission on k8s,初探

fission官网链接

fission官网截图

我用的是fission v1.0-rc1,minikube v0.31.0
参考官网安装指南
执行

$ kubectl apply -f https://github.com/fission/fission/releases/download/1.0-rc1/fission-all-1.0-rc1-minikube.yaml

下载fission-cli

$ curl -Lo fission https://github.com/fission/fission/releases/download/1.0-rc1/fission-cli-linux && chmod +x fission && sudo mv fission /usr/local/bin/

跑个例子

$ fission env create --name nodejs --image fission/node-env:1.0-rc1

此时fission-function命名空间下多了nodejs-poolmgr

$ kubectl get all -n fission-function
NAME                                         READY   STATUS    RESTARTS   AGE
pod/nodejs-poolmgr-default-86dfbfffd-44jvx   2/2     Running   0          3m11s
pod/nodejs-poolmgr-default-86dfbfffd-5lv65   2/2     Running   0          3m11s
pod/nodejs-poolmgr-default-86dfbfffd-x2stn   2/2     Running   0          3m11s

NAME                                     DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nodejs-poolmgr-default   3         3         3            3           3m11s

NAME                                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nodejs-poolmgr-default-86dfbfffd   3         3         3       3m11s

继续按照示例走,依次执行命令

$ curl -LO https://raw.githubusercontent.com/fission/fission/master/examples/nodejs/hello.js
$ fission function create --name hello --env nodejs --code hello.js
$ fission function test --name hello

这是脚本语言的,再试一个需要编译的语言的例子,java的,参考官网文档《using java with fission jvm environment》
再新建一个java的envbuilder

$ fission env create --name java --image fission/jvm-env --builder fission/jvm-builder --keeparchive --version 2

此时namespace fission-function下多了java-poolmgr(删去了上文已经列举过的nodejs-poolmgr,或者可以简单理解为这是一个新fission,新建了env java

$ kubectl get all -n fission-function
NAME                                       READY   STATUS    RESTARTS   AGE
pod/java-poolmgr-default-78674b886-9zdrh   2/2     Running   0          40s
pod/java-poolmgr-default-78674b886-rqkv2   2/2     Running   0          40s
pod/java-poolmgr-default-78674b886-z9v74   2/2     Running   0          40s

NAME                                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/java-poolmgr-default   3         3         3            3           40s

NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/java-poolmgr-default-78674b886   3         3         3       40s

而且namespace fission-builder下多了java

$ kubectl get all -n fission-builder
NAME                             READY   STATUS    RESTARTS   AGE
pod/java-1471-6bc95c6f4f-jj74f   2/2     Running   0          34s

NAME                TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)             AGE
service/java-1471   ClusterIP   10.98.54.74           8000/TCP,8001/TCP   34s

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/java-1471   1         1         1            1           34s

NAME                                   DESIRED   CURRENT   READY   AGE
replicaset.apps/java-1471-6bc95c6f4f   1         1         1       34s

把一个maven工程源码打成zip包,变成一个package

$ fission package create --env java --src java-src-pkg.zip

这时可发现,其实之前的nodejs也算一个package

$ fission package list
NAME                  BUILD_STATUS ENV
hello-js-ff04         succeeded    nodejs
java-src-pkg-zip-bqzg running      java

此时可用名字查看package的状态

$ fission package info --name java-src-pkg-zip-bqzg
Name:        java-src-pkg-zip-bqzg
Environment: java
Status:      running
Build Logs:

几次之后,待状态由running变成succeeded,即表示构建成功,logs中也有了内容,为典型的maven构建日志

$ fission package info --name java-src-pkg-zip-bqzg
Name:        java-src-pkg-zip-bqzg
Environment: java
Status:      succeeded
Build Logs:
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< io.fission:hello-world >-----------------------
[INFO] Building hello-world 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
################### 一个典型的maven构建,略 ###################
[INFO] Building jar: /packages/java-src-pkg-zip-bqzg-zml5gk/target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:48 min
[INFO] Finished at: 2018-12-26T09:03:05Z
[INFO] ------------------------------------------------------------------------

用这个package创建一个函数,并测试一下

$ fission fn create --name javatest --pkg  java-src-pkg-zip-bqzg --env java --entrypoint io.fission.HelloWorld --executortype newdeploy --minscale 1 --maxscale 1
$ fission fn test --name javatest

再list一次

$ fission env list
NAME   UID                                  IMAGE                    BUILDER_IMAGE       POOLSIZE MINCPU MAXCPU MINMEMORY MAXMEMORY EXTNET GRACETIME
java   de850fe4-08dd-11e9-8cf9-a0c589fcac3d fission/jvm-env          fission/jvm-builder 3        0      0      0         0         false  360
nodejs e8cd1872-08c0-11e9-8cf9-a0c589fcac3d fission/node-env:1.0-rc1
$ fission fn list
NAME     UID                                  ENV    EXECUTORTYPE MINSCALE MAXSCALE MINCPU MAXCPU MINMEMORY MAXMEMORY TARGETCPU
hello    841887d2-08c2-11e9-8cf9-a0c589fcac3d nodejs poolmgr      0        0        0      0      0         0         0
javatest 132ad7d5-08ef-11e9-8cf9-a0c589fcac3d java   newdeploy    1        1        0      0      0         0         80

到这里还差一环,这里调用函数都是通过fission fn test <函数名>,如何发http请求
根据官网文档《environment variables - Fission Router Address》,应该找名为routerservice

$ export FISSION_ROUTER=$(minikube ip):$(kubectl -n fission get svc router -o jsonpath='{...nodePort}')

但是这里的namespace应该是apply -f fission-<版本>.yml用的namespace
然后引入通过routehttptrigger建立网址到函数的对应。
如前所述,已有名为hello的函数,让GET /hello与之对应起来

$ fission httptrigger create --url /hello --method GET --function hello

此时有

$ fission httptrigger list
NAME                                 METHOD HOST URL    INGRESS FUNCTION_NAME
b806c861-8d11-43cc-b029-1ba5a5d6e61e GET         /hello false   hello

另一个可用的是route

$ fission route create --function javatest --url /javatest --method GET

其实,到这里对routehttptrigger进行list结果一致

$ sudo fission route list
NAME                                 METHOD HOST URL       INGRESS FUNCTION_NAME
688f773c-5c0b-473e-9494-4d8414464a86 GET         /javatest false   javatest
b806c861-8d11-43cc-b029-1ba5a5d6e61e GET         /hello    false   hello
$ sudo fission httptrigger list
NAME                                 METHOD HOST URL       INGRESS FUNCTION_NAME
688f773c-5c0b-473e-9494-4d8414464a86 GET         /javatest false   javatest
b806c861-8d11-43cc-b029-1ba5a5d6e61e GET         /hello    false   hello

踩坑记录

socat

执行两个示例命令,报错

$ fission --version
E1226 11:44:46.564885   32699 portforward.go:331] an error occurred forwarding 41541 -> 8888: error forwarding port 8888 to pod f76153aaf21cbfa3a03c6be711ac42e1157f609780bd7eaac798755239b9bf16, uid : unable to do port forwarding: socat not found.
E1226 11:44:46.566640   32699 portforward.go:331] an error occurred forwarding 41541 -> 8888: error forwarding port 8888 to pod f76153aaf21cbfa3a03c6be711ac42e1157f609780bd7eaac798755239b9bf16, uid : unable to do port forwarding: socat not found.
Warning: Error getting Fission API version: Get http://127.0.0.1:41541: EOF
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x457fe6]

goroutine 1 [running]:
github.com/fission/fission/fission/util.GetVersion(0xc4204ca450, 0x16, 0xc4204ca450, 0xc4203393d0)
    /go/src/github.com/fission/fission/fission/util/version.go:39 +0x39f
main.versionPrinter(0xc420356840)
    src/github.com/fission/fission/fission/main.go:369 +0x39
github.com/fission/fission/vendor/github.com/urfave/cli.ShowVersion(0xc420356840)
    /go/src/github.com/fission/fission/vendor/github.com/urfave/cli/help.go:206 +0x32
github.com/fission/fission/vendor/github.com/urfave/cli.(*App).Run(0xc420321380, 0xc4200d0000, 0x2, 0x2, 0x0, 0x0)
    /go/src/github.com/fission/fission/vendor/github.com/urfave/cli/app.go:224 +0x817
main.main()
    src/github.com/fission/fission/fission/main.go:50 +0x4b
$ fission env create --name nodejs --image fission/node-env:1.0-rc1
E1226 11:24:05.620541   17129 portforward.go:331] an error occurred forwarding 36535 -> 8888: error forwarding port 8888 to pod f76153aaf21cbfa3a03c6be711ac42e1157f609780bd7eaac798755239b9bf16, uid : unable to do port forwarding: socat not found.
E1226 11:24:05.621606   17129 portforward.go:331] an error occurred forwarding 36535 -> 8888: error forwarding port 8888 to pod f76153aaf21cbfa3a03c6be711ac42e1157f609780bd7eaac798755239b9bf16, uid : unable to do port forwarding: socat not found.
E1226 11:24:05.623029   17129 portforward.go:331] an error occurred forwarding 36535 -> 8888: error forwarding port 8888 to pod f76153aaf21cbfa3a03c6be711ac42e1157f609780bd7eaac798755239b9bf16, uid : unable to do port forwarding: socat not found.
Fatal error: Failed to create environment: Post http://127.0.0.1:36535/v2/environments: EOF

其中关键为

unable to do port forwarding: socat not found

于是在os中安装socat

$ sudo apt-get update && sudo apt-get install socat

参考
《安装helm服务以及搭建Helm测试环境》
helm在github上的issue#966,helm needs socat on the nodes of the k8s cluster

你可能感兴趣的:(fission on k8s,初探)