学习路线指引(点击解锁) | 知识定位 | 人群定位 |
---|---|---|
🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
💛Python量化交易实战💛 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
[root@knative-k8s-master-139 ~]# kubectl api-resources | grep "knative"
services kservice,ksvc serving.knative.dev/v1 true Service
在这里你必须有一个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 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