1. 应用的更新

1.1 更新hello-example应用

1.更新应用的环境变量

可通过命令行的方式亦可以通过读取配置文件的方式,这里主要来看命令行的方式

[root@kn-server-master01-13 knative]# kn service update --help来查看帮助

[root@kn-server-master01-13 knative]# kn service update hello \   # 更新命名空间default下的服务hello-example;
> --env TARGET=Second
Updating Service 'hello' in namespace 'default': 0.045s The Configuration is still working to reflect the latest desired specification.
2.077s Traffic is not yet migrated to the latest revision.
2.096s Ingress has not yet been reconciled.
2.123s Waiting for load balancer to be ready
2.338s Ready to serve.
服务hello-example已经更新到最新修订版本hello-00002,并且URL是http://hello.default.example.com
Service 'hello' updated to latest revision 'hello-00002' is available at URL:
http://hello.default.example.com

1.2 查看revision;

00002会取代00001吗?是的,这取决于访问的修订版本,从客户端来看,HTTP请求将全部发送到新版本的URL上,即版本已经进行了替换,从开发角度来看,两个修订版本仍然存在;

[root@kn-server-master01-13 ~]# kn revision list
NAME SERVICE TRAFFIC TAGS GENERATION AGE CONDITIONS READY REASON
hello-00002 hello 100% 2 118m 3 OK / 4 True
hello-00001 hello 1 126m 3 OK / 4 True

1.3 kn describe查看详情;

[root@kn-server-master01-13 ~]# kn revision describe hello-00002
Name: hello-00002 # 名称
Namespace: default # 所在的名称空间
Age: 2h # 运行时间
Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b) # 镜像来自哪儿
Env: TARGET=Second # 环境变量是什么
Service: hello # Srevise的名称 Conditions:
OK TYPE AGE REASON
++ Ready 2h
++ ContainerHealthy 2h
++ ResourcesAvailable 2h
I Active 2h NoTraffic OK表示服务是不是健康的,符号"++"表示一切正常
符号"I"表示服务还好,但它表示的信息没有符号"++"那么正向。如果服务出现的问题十分严重,那么会出现符号"!!"。如果服务出现的问题不是很严重,那么会出现符号"w"。如果knative不知道当前服务出现了什么问题,那么符号会变为"??";
TYPE: 这一列数据是唯一描述状态的,例如Ready表示kubernetes就绪探针探测的结果是正常的。
AGE: 这一列数据表示当前状态的最后修改时间,这个时间是会变化的。
REASON: 这列数据提供了许多排查问题的线索,例如Active状态在REASON这一栏显示的是NoTraffic状态。
Active表示什么?
当Active状态显示为NoTraffic时,表示修订版本当前没有活跃的实例在运行。假如我们对它执行curl;

1.4 访问测试;

可以看到更新后读取的是更新后的环境变量;

sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!

1.4.1 再次describe查看

这里显示的是"++Active",而不是NoTraffic,knative表达的意思是一个运行的进程被创建并且处于活跃状态,如果几分钟不访问的话,那么这个进程会再次被关闭,并且Active状态会再次回到缺少流量的状态(NoTraffic)

[root@kn-server-master01-13 ~]# kn revision describe hello-00002
Name: hello-00002
Namespace: default
Age: 2h
Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)
Replicas: 1/1
Env: TARGET=Second
Service: hello Conditions:
OK TYPE AGE REASON
++ Ready 2h
++ ContainerHealthy 2h
++ ResourcesAvailable 2h
++ Active 32s

2. 应用的镜像修改

2.1 修改实例的镜像

  1. 使用update修改具体可使用kn service update --help来查看帮助
  2. 修改环境变量会创建新的修订版本,修改镜像也会创建新的修订版本。实际上,由于没有修改环境变量,所以第三个修订版本依赖回复"Hello World:Seconds"。实际上,几乎所有对服务的更新都会创建新的修订版本;几乎所有? 有没有例外,当然有。当修改路由配置时,即更新服务的路由配置不会创建新的修订版本。
[root@kn-server-master01-13 ~]# kn service update hello --image gcr.io/knative-samples/helloworld-rust
Updating Service 'hello' in namespace 'default': 0.019s The Configuration is still working to reflect the latest desired specification.
132.577s Traffic is not yet migrated to the latest revision.
132.633s Ingress has not yet been reconciled.
132.665s Waiting for load balancer to be ready
132.850s Ready to serve.
这里说的是最新的revision叫hello-00004访问的URL是http://hello.default.example.com
Service 'hello' updated to latest revision 'hello-00004' is available at URL:
http://hello.default.example.com

2.2 查看镜像是否更新成功;

镜像确实已经被更新;而且是NoTraffic状态,因为目前没有流量;

[root@kn-server-master01-13 ~]# kn revision describe  hello-00004
Name: hello-00004
Namespace: default
Age: 9d
Image: gcr.io/knative-samples/helloworld-rust (pinned to 33fe75)
Env: TARGET=Second
Service: hello Conditions:
OK TYPE AGE REASON
++ Ready 9d
++ ContainerHealthy 9d
++ ResourcesAvailable 9d
I Active 9d NoTraffic

2.3 访问测试;

访问测试是没有问题的;

sh-3.2# curl -H "Host:hello.default.example.com" xx.xx.xx.xx
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" xx.xx.xx.xx
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" xx.xx.xx.xx
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" xx.xx.xx.xx

2.3.1 查看Pod是否被启动;

随着有流量打进来,Pod是会被启动的;

[root@kn-server-master01-13 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-00004-deployment-864974d9b6-jjh8w 2/2 Running 0 28s

3. 应用的分流

traffic允许在两个修订版本之间按照百分百分流。注意,关键是所有的流量比例加起来必须是100。如果流量比例是50和60,那么knative会返回"given traffic percents sum to 110,want 100"。 同理,如果流量比例是50和40,那么knative会返回"given traffic percents sum to 90, want 100"。我们必须保证流量比例是正确的。并且其和是100。

3.1 50/50分流

[root@kn-server-master01-13 ~]# kn service update hello \
> --traffic hello-00004=50 \
> --traffic hello-00002=50
Updating Service 'hello' in namespace 'default': 0.022s The Route is still working to reflect the latest desired specification.
0.049s Ingress has not yet been reconciled.
0.094s Waiting for load balancer to be ready
0.293s Ready to serve. Service 'hello' with latest revision 'hello-00004' (unchanged) is available at URL:
http://hello.default.example.com

3.1.1 查看revision

可以看到的是流量比例各百分之50

[root@kn-server-master01-13 ~]# kn revision list
NAME SERVICE TRAFFIC TAGS GENERATION AGE CONDITIONS READY REASON
hello-00004 hello 50% 4 9d 3 OK / 4 True
hello-00002 hello 50% 2 10d 3 OK / 4 True

3.1.2测试访问是否是正确分流;

可以看到流量差不多是均分的;

sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2#
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!

3.1.3 查看Pod的状态;

过几分钟没有访问的话,Pod会处Terminating状态

[root@kn-server-master01-13 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-00004-deployment-864974d9b6-m6vbr 2/2 Terminating 0 3m12s

3.2 多路分流

三分流量,流量在各个revision之间分发

[root@kn-server-master01-13 ~]# kn service update hello \
> --traffic hello-00004=50 \
> --traffic hello-00002=25 \
> --traffic hello-00001=25
Updating Service 'hello' in namespace 'default': 0.022s The Route is still working to reflect the latest desired specification.
0.056s Ingress has not yet been reconciled.
0.093s Waiting for load balancer to be ready
0.297s Ready to serve. Service 'hello' with latest revision 'hello-00004' (unchanged) is available at URL:
http://hello.default.example.com

3.2.1 查看revision

可以看到的是04占50%,1和2各占流量百分之25%

[root@kn-server-master01-13 ~]# kn revision list
NAME SERVICE TRAFFIC TAGS GENERATION AGE CONDITIONS READY REASON
hello-00004 hello 50% 4 9d 3 OK / 4 True
hello-00002 hello 25% 2 10d 3 OK / 4 True
hello-00001 hello 25% 1 10d 3 OK / 4 True

3.2.2 测试访问;

sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello First!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello First!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello First!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello First!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello First!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello world: Secondsh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello Second!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello First!
sh-3.2# curl -H "Host:hello.default.example.com" 10.0.0.15
Hello First!

3.2.3 describe查看状态

[root@kn-server-master01-13 ~]# kn service describe hello
Name: hello
Namespace: default
Age: 10d
URL: http://hello.default.example.com Revisions:
50% hello-00004 (current @latest) [4] (9d)
Image: gcr.io/knative-samples/helloworld-rust (pinned to 33fe75)
Replicas: 0/0
25% hello-00002 [2] (10d)
Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)
Replicas: 0/0
25% hello-00001 [1] (10d)
Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)
Replicas: 0/0 Conditions:
OK TYPE AGE REASON
++ Ready 4m
++ ConfigurationsReady 9d
++ RoutesReady 4m

3.2.4 查看Pod

可以发现3个Pod同时被拉起,等几分钟没有流量的时候会再次处于Terminating状态

[root@kn-server-master01-13 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-00001-deployment-84d5ff6489-dszfb 2/2 Running 0 39s
hello-00002-deployment-655986d86d-vgkqj 2/2 Running 0 23s
hello-00004-deployment-864974d9b6-4dhl5 2/2 Running 0 37s

3.2.5 查看revision

[root@kn-server-master01-13 ~]# kn revision describe hello-00001
Name: hello-00001
Namespace: default
Age: 10d
Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)
Replicas: 0/0
Env: TARGET=First
Service: hello Conditions:
OK TYPE AGE REASON
++ Ready 10d
++ ContainerHealthy 10d
++ ResourcesAvailable 10d
I Active 4m NoTraffic 这里显示的是no traffic没有流量

3.2.6 再次查看Pod

已经没有了Pod,已经缩容至0

[root@kn-server-master01-13 ~]# kubectl get pods
No resources found in default namespace.

Knative部署应用以及应用的更新、应用的分流(二)的更多相关文章

  1. PostgreSQL中实现更新默认值(二)

    今天我们用表继承+触发器的方案,来实现表中的更新默认值.这也许是PostgreSQL里最佳的解决方案. 一. 创建一张表,作为父表 create table basic_update( t_updat ...

  2. Weblogic下部署的应用,当更新文件时需要重新安装部署

    JSP页面检查(秒):-1 Servlet重新加载检查(秒):-1 -1说明从不检查,故当更新文件时,需要重新部署,或重新安装部署.

  3. K8S+GitLab-自动化分布式部署ASP.NET Core(三) 更新镜像版本并部署到K8S上

    一.介绍 前一篇,介绍了ASP.NET Core部署到K8S上,下面介绍我们在发布新一版本中怎么通过Gitlab CI自动给镜像打版本并部署到K8S上. 二.我们通过GitLab CI/CD 变量 不 ...

  4. CentOS 7 环境下部署 SVN 并实现自动更新(版本库放在Tomcat下)

    1.安装 SVN 1.1先检查是否有安装 svn rpm -qa subversion #没有什么显示就说明没有安装过yum remove subversion #如果有安装就运行删除老版本yum i ...

  5. spring boot 热部署 实现 前端部分热更新 详细操作

    1.前言 在以前的随笔[https://www.cnblogs.com/c2g5201314/p/12275243.html] 里面已经讲解过了 idea 如何在 springMVC 项目 实现 前端 ...

  6. Serverless之Knative部署应用实例;

    1.什么是Knative? Knative是Google2018的Google Cloud Next大会上发布的一款基于kubernetes的Serverless框架. knative的目的是在kub ...

  7. 阿里云部署,ubuntu, 连接服务器 |更新源| 安装node |安装mysql

    1.连接服务器 xshell 新建连接 ssh root@1.1.1.1 2.更新源 apt-get update 3.安装node apt-get install -y curl curl -sL ...

  8. spring boot热部署 -- 实现 后端java热更新 -- 详细操作 【idea 的 JRebel破解】

    1.前言 上一随笔写了如何使得spring boot热更新前端 ,但后端java部分无法热更新. 对于Java热更新,以前常使用  springloaded  ,但是缺点 和bug很多 无法实现真正意 ...

  9. springboot2 生产部署注意事项【持续更新】

    注意事项1. 去除不需要的 jar 开发工具 jar :springs-boot-devtools2. 监控一定要做好权限制或者去除 控制 jar :spring-boot-starter-actua ...

随机推荐

  1. 一次 MySQL 误操作导致的事故,「高可用」都顶不住了!

    这是悟空的第 152 篇原创文章 官网:www.passjava.cn 你好,我是悟空. 上次我们项目不是把 MySQL 高可用部署好了么,MySQL 双主模式 + Keepalived,来保证高可用 ...

  2. 基于bat脚本的前端发布流程的优化

    背景介绍 前面在基于bat脚本的前端发布流程设计与实现中,我已经介绍了设计与实现,这一篇主要是针对其的一个优化折腾(分两步走,第一步先搞出来,第二步再想着怎么去优化它),我主要做了以下几件事. &qu ...

  3. go-zero微服务实战系列(七、请求量这么高该如何优化)

    前两篇文章我们介绍了缓存使用的各种最佳实践,首先介绍了缓存使用的基本姿势,分别是如何利用go-zero自动生成的缓存和逻辑代码中缓存代码如何写,接着讲解了在面对缓存的穿透.击穿.雪崩等常见问题时的解决 ...

  4. Quick Pow: 如何快速求幂

    今天讲个有趣的算法:如何快速求 \(n^m\),其中 n 和 m 都是整数. 为方便起见,此处假设 m >= 0,对于 m < 0 的情况,求出 \(n^{|m|}\) 后再取倒数即可. ...

  5. Spring框架系列(10) - Spring AOP实现原理详解之AOP代理的创建

    上文我们介绍了Spring AOP原理解析的切面实现过程(将切面类的所有切面方法根据使用的注解生成对应Advice,并将Advice连同切入点匹配器和切面类等信息一并封装到Advisor).本文在此基 ...

  6. namespace_std 杂题选讲

    CF1458C Latin Square 2021 EC Final C. Random Shuffle [THUPC2021] 混乱邪恶 [JOISC2022] 制作团子 3 2022 集训队互测 ...

  7. java反序列化漏洞专项

    背景条件:java的框架,java的应用程序,使用序列化,反序列化操作非常多.在漏洞挖掘中,代码审计中,安全研究中,反序列化漏洞是个重点项,不可忽视.尤其是java应用程序的rce,10个里面有7个是 ...

  8. Windows对拍系统

    有个东西可以帮助对拍,告诉你两个程序的输出哪不一样(但是无法得知错误位置,聊胜于无吧) 一.打开计算机  二.在上方输入$cmd$,摁下回车 三.弹出对话窗如下,输入$fc +$空格,输入两个需要比较 ...

  9. springboot动态读取properties 和yml的配置

    properties使用PropertiesLoaderUtils,yml使用YamlPropertySourceLoader application.properties microsoft.def ...

  10. Grid属性太多记不住?【Grid栅格布局可视化编辑器】直观易懂高效,拖拉拽,有手就行!

    手把手教你通过拖拉拽可视化的方式带你练习[Grid栅格布局]的各个属性,直观易懂!再也不愁记不住繁多的Grid属性了.整个过程在众触应用平台进行,不用手写一行CSS代码. grid-auto-flow ...