[root@knative-k8s-master-139 ~]# kubectl api-resources | grep "knative"
services kservice,ksvc serving.knative.dev/v1 true Service
Configuration: 配置是待运行软件的期望状态,包含所需的容器镜像、环境变量等详细信息。Knative将此信息转换为底层的Kubernetes概念,例如部署。实际上,那些熟悉kubernetes的人可能知道Knative到底在做什么。即使没有Knative,开发人员也可以自己创建和提交一个部署;
Revision: 修订版本是配置的快照,每次更改配置时,Knative都会创建一个修订版本,实际上修订版本还会转换为底层Kubernetes资源。如果单纯只是保存修订版本,则有些浪费资源,毕竟Git就可以进行版本控制,为什么用Knative?因为Knative并不只是支持蓝/绿部署,实际上,Knative还支持多版本之间更详细的流量配置规则;
Route: Knative中的Route提供了一种将流量路由到正在运行代码的机制,它将一个HTTP可寻端点映射到一个或者多个Revision。可以做流量的切割和金丝雀发布;
在这里你必须有一个kubernetes集群并且安装了Knative;安装部署文档在我上篇博客有说明;
# 可以使用--help来查看如何部署;
[root@knative-k8s-master-139 ~]# kn service --help
[root@knative-k8s-master-139 ~]# kn service create --help
#
[root@knative-k8s-master-139 ~]# kn service create helloworld-example \ # name就叫做hello-example;
--image gcr.io/knative-samples/helloworld-go \ # 引用的容器镜像,使用knative提供的简单应用;
--env TRAGET="First" # 注入示例应用需要的环境变量;
Creating service 'helloworld-example' in namespace 'default': # 未指定namespace,在默认的default名称空间下;
0.042s The Route is still working to reflect the latest desired specification.
0.050s ...
0.090s Configuration "helloworld-example" is waiting for a Revision to become ready.
575.648s ...
575.679s Ingress has not yet been reconciled.
575.748s Waiting for load balancer to be ready
575.951s Ready to serve.
Service 'helloworld-example' created to latest revision 'helloworld-example-00001' is available at URL:
http://helloworld-example.default.example.com
[root@knative-k8s-master-139 ~]# kn service list
NAME URL LATEST AGE CONDITIONS READY REASON
helloworld-example http://helloworld-example.default.example.com helloworld-example-00001 12h 3 OK / 3 True
1.首先它给我们创建了一个deployment,我们可以看到此时的Pod Ready是处于0的,这是Knative独有的冷启动,在后续会说明;
[root@knative-k8s-master-139 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
helloworld-example-00001-deployment 0/0 0 0 12h
tools-test 1/1 1 1 12h
2.为我们创建了一个Service,所有的SVC都是要注册到isto-ingressgateway上面的。它提供了一个外部访问入口和一个集群内部的访问入口;
[root@knative-k8s-master-139 ~]# kubectl get svc
helloworld-example ExternalName <none> knative-local-gateway.istio-system.svc.cluster.local 80/TCP
3.我们为什么看不见创建的Pod呢?因为在没有人访问的情况下,Pod是无法启动会被置为0的状态;这就是Knative的KPA,Pod缩放至0;
[root@knative-k8s-master-139 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
tools-test-8444596cb5-rvpf9 1/1 Running 0 12h
1.我们启动一个终端访问这个Service是没有问题的;
[root@tools-test-8444596cb5-rvpf9 /]# curl helloworld-example.default.svc
Hello World!
[root@tools-test-8444596cb5-rvpf9 /]# while true; do curl --connect-timeout 1 helloworld-example.default; sleep .2; done
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
2.我们观察Pod的状态与deploy的状态,当我们持续访问的时候,Pod是会被拉起的;
[root@knative-k8s-master-139 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
helloworld-example-00001-deployment 1/1 1 1 12h
tools-test 1/1 1 1 12h
[root@knative-k8s-master-139 ~]# kubectl get pods
helloworld-example-00001-deployment-7787f5cf4f-rfwhb 2/2 Running 0 12s
tools-test-8444596cb5-rvpf9 1/1 Running 0 12h