github.com/cilium/cilium@v1.16.2/Documentation/network/servicemesh/path-types.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_ingress_path_types: 8 9 ************************** 10 Ingress Path Types Example 11 ************************** 12 13 This example walks through how various path types interact and allows you to 14 test that Cilium is working as it should. 15 16 This example requires that Cilium Ingress is enabled, and ``kubectl`` and ``jq`` 17 must be installed. 18 19 Deploy the example app 20 ====================== 21 22 This deploys five copies of the ingress-conformance-echo tool, that will allow 23 us to see what paths are forwarded to what backends. 24 25 .. code-block:: shell-session 26 27 $ # Apply the base definitions 28 $ kubectl apply -f https://raw.githubusercontent.com/cilium/cilium/examples/kubernetes/servicemesh/ingress-path-types.yaml 29 $ # Apply the Ingress 30 $ kubectl apply -f https://raw.githubusercontent.com/cilium/cilium/examples/kubernetes/servicemesh/ingress-path-types-ingress.yaml 31 32 33 Review the Ingress 34 ================== 35 36 Here is the Ingress used: 37 38 .. literalinclude:: ../../../examples/kubernetes/servicemesh/ingress-path-types-ingress.yaml 39 40 You can see here that there are five matches, one for each of our deployments. 41 42 The Ingress deliberately has the rules in a different order to what they will be 43 configured in Envoy. 44 45 * For Exact matches, we only match ``/exact`` and send that to the ``exactpath`` Service. 46 * For Prefix matches, we match ``/``, send that to the ``prefixpath`` Service, 47 and match ``/prefix`` and send that to the ``prefixpath2`` Service. 48 * For ImplementationSpecific matches, we match ``/impl.+`` (a full regex), and 49 send that to the ``implpath2`` Service. We also match ``/impl`` (without regex 50 characters) and send that to the ``implpath`` Service. 51 52 The intent here is to allow us to tell which rule we have matched by consulting 53 the echoed response from the ingress-conformance-echo containers. 54 55 Check that the Ingress has provisioned correctly 56 ================================================ 57 58 Firstly, we need to check that the Ingress has been provisioned correctly. 59 60 .. code-block:: shell-session 61 62 $ export PATHTYPE_IP=`k get ing multiple-path-types -o json | jq -r '.status.loadBalancer.ingress[0].ip'` 63 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/ | jq 64 { 65 "path": "/", 66 "host": "pathtypes.example.com", 67 "method": "GET", 68 "proto": "HTTP/1.1", 69 "headers": { 70 "Accept": [ 71 "*/*" 72 ], 73 "User-Agent": [ 74 "curl/7.81.0" 75 ], 76 "X-Envoy-External-Address": [ 77 "your-ip-here" 78 ], 79 "X-Forwarded-For": [ 80 "your-ip-here" 81 ], 82 "X-Forwarded-Proto": [ 83 "http" 84 ], 85 "X-Request-Id": [ 86 "6bb145e8-addb-4fd5-a76f-b53d07bd1867" 87 ] 88 }, 89 "namespace": "default", 90 "ingress": "", 91 "service": "", 92 "pod": "prefixpath-7cb697f5cd-wvv7b" 93 } 94 95 Here you can see that the Ingress has been provisioned correctly and is responding 96 to requests. Also, you can see that the ``/`` path has been served by the 97 ``prefixpath`` deployment, which is as expected from the Ingress. 98 99 Check that paths perform as expected 100 ==================================== 101 102 The following example uses ``jq`` to extract the first element out of the ``pod`` 103 field, which is the name of the associated deployment. So, ``prefixpath-7cb697f5cd-wvv7b`` 104 will return ``prefixpath``. 105 106 .. code-block:: shell-session 107 108 $ echo Should show "prefixpath" 109 Should show prefixpath 110 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/ | jq '.pod | split("-")[0]' 111 "prefixpath" 112 $ echo Should show "exactpath" 113 Should show exactpath 114 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/exact | jq '.pod | split("-")[0]' 115 "exactpath" 116 $ echo Should show "prefixpath2" 117 Should show prefixpath2 118 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/prefix | jq '.pod | split("-")[0]' 119 "prefixpath2" 120 $ echo Should show "implpath" 121 Should show implpath 122 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/impl | jq '.pod | split("-")[0]' 123 "implpath" 124 $ echo Should show "implpath2" 125 Should show implpath2 126 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/implementation | jq '.pod | split("-")[0]' 127 "implpath2" 128 129 (You can use the "Copy Commands" button above to do less copy-and-paste.) 130 131 The most interesting example here is the last one, where we send ``/implementation`` 132 to the ``implpath2`` Service, while ``/impl`` goes to ``implpath``. This is because 133 ``/implementation`` matches the ``/impl.+`` regex, and ``/impl`` matches the 134 ``/impl`` regex. 135 136 If we now patch the Ingress object to use the regex ``/impl.*`` instead (note the 137 ``*``, which matches **zero or more** characters of the type instead of the 138 previous ``+``, which matches **one or more** characters), then we will get a 139 different result for the last two checks: 140 141 .. code-block:: shell-session 142 143 $ echo Should show "implpath2" 144 Should show implpath 145 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/impl | jq '.pod | split("-")[0]' 146 "implpath" 147 $ echo Should show "implpath2" 148 Should show implpath2 149 $ curl -s -H "Host: pathtypes.example.com" http://$PATHTYPE_IP/implementation | jq '.pod | split("-")[0]' 150 "implpath2" 151 152 The request to ``/impl`` now matches the **longer** pattern ``/impl.*``. 153 154 The moral here is to be careful with your regular expressions! 155 156 Clean up the example 157 ==================== 158 159 Finally, we clean up our example: 160 161 .. code-block:: shell-session 162 163 $ # Apply the base definitions 164 $ kubectl delete -f https://raw.githubusercontent.com/cilium/cilium/examples/kubernetes/servicemesh/ingress-path-types.yaml 165 $ # Apply the Ingress 166 $ kubectl delete -f https://raw.githubusercontent.com/cilium/cilium/examples/kubernetes/servicemesh/ingress-path-types-ingress.yaml