Serverless for Java development

我的第一个ServerLess 程序。

前言

Server Less 适用场景:

quick start [ fnproject]

kubeless [ 整理中]

* kubeless function1.yaml

        
  ---
apiVersion: k8s.io/v1
kind: Function
metadata:
  name: function1
spec:
  handler: hello.foobar
  image: registry.timeondata.com/firsh_demo/kubeless_runtime_python:2.7.1
  runtime: python2.7
  deps: |
    cowpy
  function: |
      import time
      import random
      from cowpy import cow
      def foobar():
        # NB: delay will be negative and sleep will raise an error
        # occasionally.  This is a feature for demoing errors.
        delay = random.normalvariate(0.3, 0.2)
        time.sleep(delay)
        msg = "hello world - with a %0.2fs artificial delay" % delay
        c = cow.get_cow()
        return c().milk(msg)
        
    

* 启动

        
  ➜ python git:(master) ✗ kubectl create -f function1.yaml

        
    

* 检查启动

        
 # 检查启动
 ➜  python git:(master) ✗ kubeless function ls
NAME     	NAMESPACE	HANDLER     	RUNTIME  	TYPE	TOPIC	DEPENDENCIES	STATUS
function1	default  	hello.foobar	python2.7	    	     	cowpy       	1/1 READY
        
    

* 测试调用

        
    kubeless function call  function1 
        
    

* 结果

        

➜  python git:(master) ✗ kubeless function call  function1
 _____________________________________________
< hello world - with a 0.42s artificial delay >
 ---------------------------------------------
     \   ^__^
      \  (oo)\_______
         (__)\       )\/\
           ||----w |
           ||     ||

        
    

转载请注明出处,本文采用 CC4.0 协议授权