github.com/cilium/cilium@v1.16.2/Documentation/network/servicemesh/envoy-traffic-shifting.rst (about) 1 .. only:: not (epub or latex or html) 2 3 WARNING: You are looking at unreleased Cilium documentation. 4 Please use the official rendered version released here: 5 https://docs.cilium.io 6 7 .. _gs_envoy_traffic_shifting: 8 9 ******************* 10 L7 Traffic Shifting 11 ******************* 12 13 Cilium Service Mesh defines a ``CiliumEnvoyConfig`` CRD which allows users 14 to set the configuration of the Envoy component built into Cilium agents. 15 16 This example sets up an Envoy listener which load balances requests 17 to the helloworld Service by sending 90% of incoming requests to the 18 backend ``helloworld-v1`` and 10% of incoming requests to the backend 19 ``helloworld-v2``. 20 21 Deploy Test Applications 22 ======================== 23 24 .. parsed-literal:: 25 26 $ kubectl apply -f \ |SCM_WEB|\/examples/kubernetes/servicemesh/envoy/client-helloworld.yaml 27 28 The test workloads consist of: 29 30 - One client Deployment, ``client`` 31 - Two server Deployments, ``helloworld-v1`` and ``helloworld-v2`` 32 33 View information about these Pods and the helloworld Service: 34 35 .. code-block:: shell-session 36 37 $ kubectl get pods --show-labels -o wide 38 NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS 39 client-64848f85dd-sjfmb 1/1 Running 0 2m23s 10.0.0.206 cilium-control-plane <none> <none> kind=client,name=client,pod-template-hash=64848f85dd 40 helloworld-v1-5845f97d6b-gkdtk 1/1 Running 0 2m23s 10.0.0.241 cilium-control-plane <none> <none> app=helloworld,pod-template-hash=5845f97d6b,version=v1 41 helloworld-v2-7d55d87964-ns9kh 1/1 Running 0 2m23s 10.0.0.251 cilium-control-plane <none> <none> app=helloworld,pod-template-hash=7d55d87964,version=v2 42 43 $ kubectl get svc --show-labels 44 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE LABELS 45 helloworld ClusterIP 10.96.194.77 <none> 5000/TCP 8m27s app=helloworld,service=helloworld 46 47 Apply weight-based routing 48 ========================== 49 50 Make an environment variable with the Pod name for client: 51 52 .. code-block:: shell-session 53 54 $ export CLIENT=$(kubectl get pods -l name=client -o jsonpath='{.items[0].metadata.name}') 55 56 Try making several requests to the helloworld Service. 57 58 .. code-block:: shell-session 59 60 $ for i in {1..10}; do kubectl exec -it $CLIENT -- curl helloworld:5000/hello; done 61 62 The test results are as follows:: 63 64 Hello version: v2, instance: helloworld-v2-7d55d87964-ns9kh 65 Hello version: v2, instance: helloworld-v2-7d55d87964-ns9kh 66 Hello version: v2, instance: helloworld-v2-7d55d87964-ns9kh 67 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 68 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 69 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 70 Hello version: v2, instance: helloworld-v2-7d55d87964-ns9kh 71 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 72 Hello version: v2, instance: helloworld-v2-7d55d87964-ns9kh 73 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 74 75 The test results were as expected. Of the requests sent to the helloworld service, 76 50% of them were sent to the backend ``helloworld-v1`` and 50% of them were sent to 77 the backend ``helloworld-v2``. 78 79 ``CiliumEnvoyConfig`` can be used to load balance traffic destined to one Service to a 80 group of backend Services. To load balance traffic to the helloworld Service, first create 81 individual Services for each backend Deployment. 82 83 .. parsed-literal:: 84 $ kubectl apply -f \ |SCM_WEB|\/examples/kubernetes/servicemesh/envoy/helloworld-service-v1-v2.yaml 85 86 Apply the ``envoy-helloworld-v1-90-v2-10.yaml`` file, which defines a ``CiliumEnvoyConfig`` 87 to send 90% of traffic to the helloworld-v1 Service backend and 10% of traffic to the helloworld-v2 Service backend: 88 89 .. parsed-literal:: 90 $ kubectl apply -f \ |SCM_WEB|\/examples/kubernetes/servicemesh/envoy/envoy-helloworld-v1-90-v2-10.yaml 91 92 View information about these Pods and Services: 93 94 .. code-block:: shell-session 95 96 $ kubectl get pods --show-labels -o wide 97 NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS 98 client-64848f85dd-sjfmb 1/1 Running 0 2m23s 10.0.0.206 cilium-control-plane <none> <none> kind=client,name=client,pod-template-hash=64848f85dd 99 helloworld-v1-5845f97d6b-gkdtk 1/1 Running 0 2m23s 10.0.0.241 cilium-control-plane <none> <none> app=helloworld,pod-template-hash=5845f97d6b,version=v1 100 helloworld-v2-7d55d87964-ns9kh 1/1 Running 0 2m23s 10.0.0.251 cilium-control-plane <none> <none> app=helloworld,pod-template-hash=7d55d87964,version=v2 101 102 $ kubectl get svc --show-labels 103 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE LABELS 104 helloworld ClusterIP 10.96.194.77 <none> 5000/TCP 16m app=helloworld,service=helloworld 105 helloworld-v1 ClusterIP 10.96.0.240 <none> 5000/TCP 4s app=helloworld,service=helloworld,version=v1 106 helloworld-v2 ClusterIP 10.96.41.142 <none> 5000/TCP 4s app=helloworld,service=helloworld,version=v2 107 108 .. include:: warning.rst 109 110 Try making several requests to the helloworld Service again. 111 112 .. code-block:: shell-session 113 114 $ for i in {1..10}; do kubectl exec -it $CLIENT -- curl helloworld:5000/hello; done 115 116 The test results are as follows:: 117 118 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 119 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 120 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 121 Hello version: v2, instance: helloworld-v2-7d55d87964-ns9kh 122 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 123 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 124 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 125 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 126 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 127 Hello version: v1, instance: helloworld-v1-5845f97d6b-gkdtk 128 129 The test results were as expected. Of the requests sent to the helloworld service, 130 90% of them were sent to the backend ``helloworld-v1`` and 10% of them were sent to 131 the backend ``helloworld-v2``. 132 133 Cleaning up 134 =========== 135 136 Remove the rules. 137 138 .. parsed-literal:: 139 140 $ kubectl delete -f \ |SCM_WEB|\/examples/kubernetes/servicemesh/envoy/envoy-helloworld-v1-90-v2-10.yaml 141 142 Remove the test application. 143 144 .. parsed-literal:: 145 146 $ kubectl delete -f \ |SCM_WEB|\/examples/kubernetes/servicemesh/envoy/client-helloworld.yaml 147 $ kubectl delete -f \ |SCM_WEB|\/examples/kubernetes/servicemesh/envoy/helloworld-service-v1-v2.yaml