Careful!
You are browsing documentation for a version of Kuma that is not the latest release.
Migration to the new policies
Kuma provides two set of policies to configure proxies. The original source/destination policies, while provided a lot of features, haven’t met users expectations in terms of flexibility and transparency. The new targetRef policies were designed to preserve what already worked well, and enhance the matching functionality and overall UX.
In this guide, we’re going to setup a demo with old policies and then perform a migration to the new policies.
Prerequisites
helm
- a package manager for Kuberneteskind
- a tool for running local Kubernetes clustersjq
- a command-line JSON processorjd
- a command-line utility to visualise JSONPatch
Start Kubernetes cluster
Start a new Kubernetes cluster on your local machine by executing:
You can skip this step if you already have a Kubernetes cluster running. It can be a cluster running locally or in a public cloud like AWS EKS, GCP GKE, etc.
Install Kuma
Install Kuma control plane with skipMeshCreation
set to true
by executing:
Make sure the list of meshes is empty:
Expected output:
Setup demo with old policies
In the first half of this guide we’re going to deploy a demo app in the default
mesh and configure it using old policies.
Create default
mesh
Deploy demo application
- Deploy the application
-
Port-forward the service to the namespace on port 5000:
- In a browser, go to 127.0.0.1:5000 and increment the counter.
Enable mTLS and deploy TrafficPermissions
Deploy TrafficRoute
Deploy Timeouts
Deploy CircuitBreaker
Migration steps
It’s time to migrate the demo app to the new policies.
Each type of policy can be migrated separately; for example, once we have completely finished with the Timeout
s,
we will proceed to the next policy type, CircuitBreakers
.
It’s possible to migrate all policies at once, but small portions are preferable as they’re easily reversible.
The generalized migration process roughly consists of 4 steps:
- Create a new targetRef policy as a replacement for existing source/destination policy (do not forget about default policies that might not be stored in your source control). The corresponding new policy type can be found in the table. Deploy the policy in shadow mode to avoid any traffic disruptions.
- Using Inspect API review the list of changes that are going to be created by the new policy.
- Remove
kuma.io/effect: shadow
label so that policy is applied in a normal mode. - Observe metrics, traces and logs. If something goes wrong change policy’s mode back to shadow and return to the step 2. If everything is fine then remove the old policies.
The order of migrating policies generally doesn’t matter, except for the TrafficRoute policy, which should be the last one deleted when removing old policies. This is because many old policies, like Timeout and CircuitBreaker, depend on TrafficRoutes to function correctly.
TrafficPermission -> MeshTrafficPermission
-
Create a replacement policy for
app-to-redis
TrafficPermission and apply it withkuma.io/effect: shadow
label: -
Check the list of changes for the
redis_kuma-demo_svc_6379
kuma.io/service
in Envoy configuration usingkumactl
,jq
andjd
:Expected output:
As we can see, the only difference is the policy name
MeshTrafficPermission
instead ofallow-all-default
. The value of the policy is the same. -
Remove the
kuma.io/effect: shadow
label:Even though the old TrafficPermission and the new MeshTrafficPermission are both in use, the new policy takes precedence, making the old one ineffective.
-
Check that the demo app behaves as expected. If everything goes well, we can safely remove TrafficPermissions:
Timeout -> MeshTimeout
-
Create a replacement policy for
timeout-global
Timeout and apply it withkuma.io/effect: shadow
label: -
Check the list of changes for the
redis_kuma-demo_svc_6379
kuma.io/service
in Envoy configuration usingkumactl
,jq
andjd
:Expected output:
Review the list and ensure the new MeshTimeout policy won’t change the important settings. The key differences between old and new timeout policies:
- Previously, there was no way to specify
requestHeadersTimeout
,maxConnectionDuration
andmaxStreamDuration
(on inbound). These timeouts were unset. With the new MeshTimeout policy we explicitly set them to0s
by default. idleTimeout
was configured both on the cluster and listener. MeshTimeout configures it only on the cluster.route/idleTimeout
is duplicated value ofstreamIdleTimeout
but per-route. Previously we’ve set it only per-listener.
These 3 facts perfectly explain the list of changes we’re observing.
- Previously, there was no way to specify
-
Remove the
kuma.io/effect: shadow
label.Even though the old Timeout and the new MeshTimeout are both in use, the new policy takes precedence, making the old one ineffective.
-
Check that the demo app behaves as expected. If everything goes well, we can safely remove Timeouts:
CircuitBreaker -> MeshCircuitBreaker
-
Create a replacement policy for
cb-global
CircutBreaker and apply it withkuma.io/effect: shadow
label: -
Check the list of changes for the
redis_kuma-demo_svc_6379
kuma.io/service
in Envoy configuration usingkumactl
,jq
andjd
:The expected output is empty. CircuitBreaker and MeshCircuitBreaker configures Envoy in the exact similar way.
-
Remove the
kuma.io/effect: shadow
label.Even though the old CircuitBreaker and the new MeshCircuitBreaker are both in use, the new policy takes precedence, making the old one ineffective.
-
Check that the demo app behaves as expected. If everything goes well, we can safely remove CircuitBreakers:
TrafficRoute -> MeshTCPRoute
It’s safe to simply remove route-all-default
TrafficRoute.
Traffic will flow through the system even if there are neither TrafficRoutes nor MeshTCPRoutes/MeshHTTPRoutes.
MeshGatewayRoute -> MeshHTTPRoute/MeshTCPRoute
The biggest change is that there are now 2 protocol specific routes, one for TCP
and one for HTTP. MeshHTTPRoute
always takes precedence over MeshTCPRoute
if
both exist.
Otherwise the high-level structure of the routes hasn’t changed, though there are a number of details to consider. Some enum values and some field structures were updated, largely to reflect Gateway API.
Please first read the MeshGatewayRoute
docs, the MeshHTTPRoute
docs
and the MeshTCPRoute
docs.
Always refer to the spec to ensure your new resource is valid.
Note that MeshHTTPRoute
has precedence over MeshGatewayRoute
.
We’re going to start with a gateway and simple legacy MeshGatewayRoute
,
look at how to migrate MeshGatewayRoutes
in general
and then finish with migrating our example MeshGatewayRoute
.
Let’s start with the following MeshGateway
and MeshGatewayInstance
:
and the following initial MeshGatewayRoute
:
Targeting
The main consideration is specifying which gateways are affected by the route.
The most important change is that instead of
solely using tags to select MeshGateway
listeners,
new routes target MeshGateways
by name and optionally with tags for specific
listeners.
So in our example:
becomes:
because we’re now using the name of the MeshGateway
instead of the kuma.io/service
it matches.
Spec
As with all new policies, the spec is now merged under a default
field.
MeshTCPRoute
is very simple, so the rest of this is focused on
MeshHTTPRoute
.
Note that for MeshHTTPRoute
the hostnames
are directly under the to
entry:
becomes:
Matching
Matching works the same as before. Remember that for MeshHTTPRoute
that merging is done on a match
basis. So it’s possible for one route to define filters
and another
backendRefs
for a given match, and the resulting rule would both apply the filters and route to the
backends.
Given two routes, one with:
and the other:
Traffic to /
would have the x-custom-header
added and be sent to the backend
.
Filters
Every MeshGatewayRoute
filter has an equivalent in MeshHTTPRoute
.
Consult the documentation for both resources to
find out how each filter looks in MeshHTTPRoute
.
Backends
Backends are similar except that instead of targeting with tags, the targetRef
structure with kind: MeshService
/kind: MeshServiceSubset
is used.
Equivalent MeshHTTPRoute
So all in all we have:
-
Create the equivalent MeshHTTPRoute
-
Check that traffic is still working.
-
Delete the previous MeshGatewayRoute:
Next steps
- Further explore new policies