In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Cdn.com/833c7ecf05588f257bcf7071d0f7b0d3b7aa298e.png ">
Author | Dongdao Aliyun Container platform engineer
Introduction: although Knative supports WebSocket and gRPC by default, you will find that sometimes you want to deploy your own WebSocket or gRPC to Knative. Although the final investigation found that most of them are caused by their own program problems or configuration errors. This article gives an example of WebSocket and gRPC respectively. When you need to deploy related services in a production or test environment, you can use the examples given in this article to test Knative services.
WebSocket
If you manually configure Istio Gateway to support WebSocket, you need to enable the websocketUpgrade feature. But using Knative Serving deployment actually comes with this capability. The complete code for this example is on https://github.com/knative-sample/websocket-chat, which is an example of a group chat based on WebSocket implementation.
Using a browser to connect to the deployed service, you can see a window to receive information and a window to send information. When you send a message, all connected users will receive your message. So you can use two browser windows to connect to the service, one window to send messages and one window to receive messages to verify that the WebSocket service is working.
This example makes some optimizations based on gorilla/websocket:
Vendor dependency is added to the code. When you download it, you can directly use the yaml file (service.yaml) with Dockerfile and Makefile added to compile binary and Knative Sevice added to the image. You can submit it to the Knative cluster or use the compiled image registry.cn-hangzhou.aliyuncs.com/knative-sample/websocket-chat:2019-10-15 directly.
Knative Service configuration:
ApiVersion: serving.knative.dev/v1kind: Servicemetadata: name: websocket-chatspec: template: spec: containers:-image: registry.cn-hangzhou.aliyuncs.com/knative-sample/websocket-chat:2019-10-15 ports:-name: http1 containerPort: 8080
After the code clone comes down, execute kubectl apply-f service.yaml to deploy the service to Knative, and then access the service address directly to use it.
View the ksvc list and get the access domain name.
└─ # kubectl get ksvcNAME URL LATESTCREATED LATESTREADY READY REASONwebsocket-chat http://websocket-chat.default.serverless.kuberun.com websocket-chat-7ghc9 websocket-chat-7ghc9 True
Now open http://websocket-chat.default.serverless.kuberun.com using a browser and you can see the group chat window.
Open two windows and send a message in one window, and the other window receives the message through WebSocket.
GRPC
GRPC cannot be accessed directly through the browser and needs to interact with the server side through the client side. The complete code for this example is placed in https://github.com/knative-sample/grpc-ping-go, and this example gives a directly usable image to test the gRPC service.
Knative Service configuration:
ApiVersion: serving.knative.dev/v1kind: Servicemetadata: name: grpc-pingspec: template: spec: containers:-image: registry.cn-hangzhou.aliyuncs.com/knative-sample/grpc-ping-go:2019-10-15 ports:-name: H3C containerPort: 8080
After the code clone comes down, execute kubectl apply-f service.yaml to deploy the service to Knative.
Get the ksvc list and access domain name:
└─ # kubectl get ksvcNAME URL LATESTCREATED LATESTREADY READY REASONgrpc-ping http://grpc-ping.default.serverless.kuberun.com grpc-ping-p2tft Unknown RevisionMissingwebsocket-chat http://websocket-chat.default.serverless.kuberun.com websocket-chat-6hgld websocket-chat-6hgld True
Now that we know that the address of gRPC server is grpc-ping.default.serverless.kuberun.com and port 80, we can initiate a test request:
└─ # docker run-- rm registry.cn-hangzhou.aliyuncs.com/knative-sample/grpc-ping-go:2019-10-15 / client-server_addr= "grpc-ping.default.serverless.kuberun.com:80"-insecure2019/10/16 11:35:07 Ping got hello-pong2019/10/16 11:35:07 Got pong2019-10-16 11 Mongo 07.854794231 + 0800 CST massif 73.0619090522019 10 Greg 16 11:35:07 Got pong2019-10-16 11:35:07 . 854827273 + 0800 CST masks 73.061942072201919 Greater 16 11:35:07 Got pong 2019-10-16 111951 CST massively 73.0619506062019191910 pedigree 16 11:35:07 Got pong 2019-10-16 11 Univer 357.854842843 + 0800 CST massifs 73.0619576432019191919 10-16 1111 CST masks 07.854849211 + 0800 CST masks 73.06196401220191919191919191919191916114561964012201919191916 11:35:07 Got pong 2019-10-16 11ther 357.854855249 + 0800 CST mbands 73.061974920 1919 / 0800 10 CST 16 11:35:07 Got pong 2019-10-16 11 Got pong 515 07.854861659 + 0800 CST masks 73.061976460201919 Grey 10 Grease 16 11:35:07 Got pong 2019-10-16 11 Got pong 2019-10-16 11 CST motions 07.854875071 + 0800 CST masks 73.0619898732033.0619898732016 11:35:07 Got pong 2019-10-16 11 Got pong purse 357.854905416 + 0800 CST masks 73.0620202219Thus 1016 11:35:07 Got pong 2019-10-16 1118 RAR 3515 07.85491183 + 0800 CST masks 73.0620266301910 Got pong 2019-10-16 11 Got pong 515 07.85492533 + 0800 CST maser 73.062040133201910 CST 10 11:35:07 Got pong 2019-10-16 111VOUR 07.854932285 + 0800 CST massif 33.00620470832019 Plus 10 peg 16 11:35:07 Got pong 2019-10-16 11 Got pong 2019-16 11Vera 3507.854946977 + 0800 CST mumber 2019-0800 CST maser 2019-10 2082201919 UG1016 11:35:07 Got pong 2019-10-16 11 color 3518 purposed 07.854953311 + 0800 CST maser 73.062068112201910-16 11:35:07 Got pong 2019-10-16 11 : 35 CST 07.854966639 + 0800 CST massif 73.0620814401919Accord 1016 11:35:07 Got pong 2019-10-16 11 Freud 357.854973939 + 0800 CST massif 73.062088739201919Uniplic10 peg 16 11:35:07 Got pong 2019-10-16 11VOV 350purr 7.854985463 + 0800 CST maser 73.06210026820191910 Accord 16 11:35:07 Got pong 2019-10-16 11 CST Mutter 07.854993275 + 0800 CST maser 73.006210807320191016, 01016 Got pong 2019-10-16-11 Rod 3535 Rod 7.854999812 + 0800 CST A summary of 73.0621146132019 Got pong 10 racing 16 11:35:07 Got pong 2019-10-16 11 35 purse 07.855012676 + 0800 massif 73.062127479
This article shows the deployment methods of WebSocket and gRPC through two examples:
The WebSocket sample shows the process of sending and receiving messages gRPC shows the process of gRPC remote call by launching a client.
Brief introduction of the author:
Dongdao, an engineer of Aliyun container platform, is responsible for the Knative related work of Aliyun container platform.
Learn more about ACK: https://www.aliyun.com/product/kubernetes
"Alibaba Yun × × icloudnative × × erverless, containers, Service Mesh and other technical fields, focusing on cloud native popular technology trends, cloud native large-scale landing practice, to do the best understanding of cloud native development × ×
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.