In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to achieve application traffic replication through K8S Ingress Controller. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's follow the editor to have a look.
How to replicate the traffic of applications in different K8S clusters of Ali Cloud CCS
Simulation test
Usually, when the system carries out major reconfiguration or releases new functions, we need to carry out pressure testing to evaluate the carrying capacity of the new system in advance. Traditionally, we usually test the new system by simulating all kinds of test data online in the offline environment. But this method often can not effectively simulate the real online traffic, especially the abnormal traffic mixed with all kinds of colors in the normal traffic. In view of this situation, we can simulate and test the new system by copying the online application traffic to the specified offline environment. In another case, if our online system encounters a performance bottleneck, but can not quickly locate the problem, we can also use traffic replication to direct the real traffic of the application to the offline environment for location. The following is mainly to share with you how to replicate the traffic of applications in different K8S clusters of Ali Cloud CCS:
Deploy basic applications
It is assumed that you have applied for two different K8S clusters in the Ali Cloud CCS console (tentatively one is K8S Product Cluster and the other is K8S Stage Cluster).
First, deploy an application in K8S Product Cluster and expose service access through Ingress:
ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: # currently configured as the old version image-image: registry.cn-hangzhou.aliyuncs.com/xianlu/old-nginx imagePullPolicy: Always name: nginx ports:-containerPort: 80 Protocol: TCP restartPolicy: Always---apiVersion: v1kind: Servicemetadata: name: nginx-servicespec: ports:-port: 80 protocol: TCP targetPort: 80 selector: app: nginx type: NodePort---apiVersion: extensions/v1beta1kind: Ingressmetadata: name: nginx-ingressspec: rules: # here configuration uses the cluster default domain name (you can also use a custom domain name for DNS resolution)-host: nginx.c37bf6b77bded43669ba2fb67448b4146.cn-hangzhou.alicontainer .com http: paths:-path: / backend: serviceName: nginx-service servicePort: 80
2. After the deployment is completed, you can use the following command to test the access:
# View the ingress configuration of the application kubectl get ing nginx-ingressNAME HOSTS ADDRESS PORTS AGEnginx-ingress nginx.c37bf6b77bded43669ba2fb67448b4146.cn-hangzhou.alicontainer.com 47.110.199.44 808m # test access to the application domain name curl http://nginx.c37bf6b77bded43669ba2fb67448b4146.cn-hangzhou.alicontainer.comold
3. Deploy the same application in K8S Stage Cluster and expose service access through Ingress:
ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: # currently configured as the new version image-image: registry.cn-hangzhou.aliyuncs.com/xianlu/new-nginx imagePullPolicy: Always name: nginx ports:-containerPort: 80 Protocol: TCP restartPolicy: Always---apiVersion: v1kind: Servicemetadata: name: nginx-servicespec: ports:-port: 80 protocol: TCP targetPort: 80 selector: app: nginx type: NodePort---apiVersion: extensions/v1beta1kind: Ingressmetadata: name: nginx-ingressspec: rules: # here configuration uses the cluster default domain name (you can also use a custom domain name for DNS resolution)-host: nginx.c41eb6ca34a3e49f7aea63b8bc9e8ad98.cn-beijing.alicontainer .com http: paths:-path: / backend: serviceName: nginx-service servicePort: 80
4. After the deployment is completed, you can use the following command to test the access:
# View the ingress configuration of the application kubectl get ing nginx-ingressNAME HOSTS ADDRESS PORTS AGEnginx-ingress nginx.c41eb6ca34a3e49f7aea63b8bc9e8ad98.cn-beijing.alicontainer.com 39.106.233.1 80 1m # test access application domain name curl http://nginx.c41eb6ca34a3e49f7aea63b8bc9e8ad98.cn-beijing.alicontainer.comnew configure traffic replication
Suppose we want to copy 100% of the access traffic of the application in K8S Product Cluster to the corresponding application service in K8S Stage Cluster, and copy and forward a copy of all requests for access to the domain name nginx.c37bf6b77bded43669ba2fb67448b4146.cn-hangzhou.alicontainer.com to nginx.c41eb6ca34a3e49f7aea63b8bc9e8ad98.cn-beijing.alicontainer.com:
Cdn.com/fd9845ba32c0dd0fd7322a8e90db229eeeb0827f.png ">
Note: since K8S Stage Cluster Ingress only serves as the receiver of replication traffic, it does not need to make any configuration changes. Here, we only need to configure it on K8S Product Cluster Ingress.
Configure the percentage of replication traffic and the application domain name that receives replication traffic
Use the following command to modify the ConfigMap configuration of K8S Ingress Controller and add http-snippet configuration fragments to configure the desired percentage of replication traffic and the target application domain name that receives replication traffic:
~ kubectl-n kube-system edit cm nginx-configuration
Configure the following KV pairs:
Http-snippet: | split_clients "$date_gmt" >
2. Configure traffic replication
Here, we use configuration-snippet and server-snippet to modify the traffic replication configuration of the source Ingress added application (see YAML below):
ApiVersion: extensions/v1beta1kind: Ingressmetadata: name: nginx-ingress annotations: nginx.ingress.kubernetes.io/configuration-snippet: | mirror / mirror; nginx.ingress.kubernetes.io/server-snippet: | location = / mirror {internal; set $shadow_service_name "nginx-product-service"; proxy_set_header X-Shadow-Service $shadow_service_name; proxy_pass http://$mirror_servers$request_uri; } spec: rules:-host: nginx.c37bf6b77bded43669ba2fb67448b4146.cn-hangzhou.alicontainer.com http: paths:-path: / backend: serviceName: nginx-service servicePort: 80
At this point, the application traffic replication configuration based on K8S Ingress Controller has been completed.
Test traffic replication
Here we try to access the application domain name nginx.c37bf6b77bded43669ba2fb67448b4146.cn-hangzhou.alicontainer.com in K8S Product Cluster. We can see that each time a request is made for the Ingress application domain name in K8S Product Cluster, it will copy the same request and forward it to the corresponding application service in K8S Stage Cluster:
At the same time, because we configured proxy_set_header X-Shadow-Service $shadow_service_name in the traffic replication configuration, the requests received by the K8S Stage Cluster target application will carry a X-Shadow-Service header to indicate which online application the mirror traffic comes from.
The above is how to achieve application traffic replication through K8S Ingress Controller. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.