Knative部署应用以及应用的更新、应用的分流(二)
🚀 優質資源分享 🚀
| 🧡 Python實戰微信訂餐小程序 🧡 | 進階級 | 本課程是python flask+微信小程序的完美結合,從項目搭建到騰訊云部署上線,打造一個全棧訂餐系統。 |
| 💛Python量化交易實戰💛 | 入門級 | 手把手帶你打造一個易擴展、更安全、效率更高的量化交易系統 |
- 1. 應用的更新
- 1.1 更新hello-example應用
- 1.2 查看revision;
- 1.3 kn describe查看詳情;
- 1.4 訪問測試;
- 2. 應用的鏡像修改
- 2.1 修改實例的鏡像
- 2.2 查看鏡像是否更新成功;
- 2.3 訪問測試;
- 3. 應用的分流
- 3.1 50/50分流
- 3.2 多路分流
1. 應用的更新
1.1 更新hello-example應用
1.更新應用的環境變量
可通過命令行的方式亦可以通過讀取配置文件的方式,這里主要來看命令行的方式
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 True1.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 NoTrafficOK表示服務是不是健康的,符號"++"表示一切正常 符號"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: helloConditions: OK TYPE AGE REASON++ Ready 2h ++ ContainerHealthy 2h ++ ResourcesAvailable 2h ++ Active 32s2. 應用的鏡像修改
2.1 修改實例的鏡像
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: helloConditions: OK TYPE AGE REASON++ Ready 9d ++ ContainerHealthy 9d ++ ResourcesAvailable 9d I Active 9d NoTraffic2.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.xx2.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 28s3. 應用的分流
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 ready0.293s Ready to serve.Service 'hello' with latest revision 'hello-00004' (unchanged) is available at URL: http://hello.default.example.com3.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 True3.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 3m12s3.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 ready0.297s Ready to serve.Service 'hello' with latest revision 'hello-00004' (unchanged) is available at URL: http://hello.default.example.com3.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 True3.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.comRevisions: 50% hello-00004 (current @latest) [4] (9d)Image: gcr.io/knative-samples/helloworld-rust (pinned to 33fe75)Replicas: 0/025% hello-00002 [2] (10d)Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)Replicas: 0/025% hello-00001 [1] (10d)Image: gcr.io/knative-samples/helloworld-go (pinned to 5ea96b)Replicas: 0/0Conditions: OK TYPE AGE REASON++ Ready 4m ++ ConfigurationsReady 9d ++ RoutesReady 4m3.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 37s3.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: helloConditions: 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部署应用以及应用的更新、应用的分流(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Serverless之Knative部署
- 下一篇: 守住自己的本心