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
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
[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;
可以看到更新后读取的是更新后的环境变量;
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!
这里显示的是"++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
[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
镜像确实已经被更新;而且是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
访问测试是没有问题的;
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
随着有流量打进来,Pod是会被启动的;
[root@kn-server-master01-13 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-00004-deployment-864974d9b6-jjh8w 2/2 Running 0 28s
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。
[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
可以看到的是流量比例各百分之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
可以看到流量差不多是均分的;
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!
过几分钟没有访问的话,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
三分流量,流量在各个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
可以看到的是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
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!
[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个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
[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没有流量
已经没有了Pod,已经缩容至0
[root@kn-server-master01-13 ~]# kubectl get pods
No resources found in default namespace.
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
是否可以在应用程序中包含的gem代码中知道应用程序的Rails文件系统根目录?这是gem来源的示例:moduleMyGemdefself.included(base)putsRails.root#returnnilendendActionController::Base.send:include,MyGem谢谢,抱歉我的英语不好 最佳答案 我发现解决类似问题的解决方案是使用railtie初始化程序包含我的模块。所以,在你的/lib/mygem/railtie.rbmoduleMyGemclassRailtie使用此代码,您的模块将在