You can switch between internal protocol forwarding and Internal TCP/UDP Load Balancing
by updating the forwarding rule with the set-target
command as described on this
page. When switching between internal protocol forwarding and
Internal TCP/UDP Load Balancing, you don't need to delete and re-create the
forwarding rule. The forwarding rule continues to use the same internal
IPv4 address (whether static or ephemeral).
You can also switch between a target instance and backend service by deleting and re-creating the forwarding rule. However, this method requires a static IPv4 address in order to use the same address with the new forwarding rule. Deleting and re-creating the forwarding rule is the only way to switch between external protocol forwarding and backend service-based external TCP/UDP Network Load Balancing.
The following diagram shows an example using internal protocol forwarding.
A target instance does not specify any protocol–it inherits the protocols and ports of the forwarding rule. However, when switching a forwarding rule to reference a backend service, you must ensure the IP protocol of the forwarding rule and the protocol of the backend service are compatible as shown in the following table:
Forwarding rule protocol | Backend service protocol |
---|---|
TCP |
TCP or UNSPECIFIED |
UDP |
UDP or UNSPECIFIED |
L3_DEFAULT For external protocol forwarding only |
UNSPECIFIED |
To change a forwarding rule from pointing to a target instance to pointing to a regional backend service:
gcloud compute forwarding-rules set-target FORWARDING_RULE \ --backend-service=BACKEND_SERVICE
You can then transition back to a target instance:
gcloud compute forwarding-rules set-target FORWARDING_RULE \ --target-instance=TARGET_INSTANCE \ --target-instance-zone=ZONE