VKE allows you to configure the IP mode of the LoadBalancer Service by using annotations. In this way, traffic can be directly forwarded within clusters, or all traffic can be forwarded to CLB instances. This topic describes the principles and configuration methods of different IP modes.
In a VKE cluster, for the Service of the LoadBalancer type, the IP mode determines the traffic forwarding path within the cluster (especially in scenarios when internal pods access the Service). The main difference between IP modes is whether the traffic passes through an external CLB instance. The following table describes the details of different modes.
- A cluster has been created and meets the following requirements: For details, see Creating clusters.
- The cluster Kubernetes version is v1.30 or later. If the cluster version is outdated, upgrade it first. For details, see Upgrading clusters.
- The cluster uses the VPC-CNI network model, with IPvlan as the pod network interface and eBPF as the Service forwarding mode. For the method of querying cluster information, see Cluster basic information.
- The cloud-controller-manager add-on has been installed and upgraded to v1.43.0 or later. For details, see Upgrading add-ons.
When the IP mode is set to Proxy, the client pod and server pod cannot run on the same node. When the IP mode is set to Proxy, the client pod and the server pod cannot run on the same node. This is because when a request from a client pod is forwarded by the CLB instance to a server pod on the same node, the CLB instance may retain the source IP of the client. Since the source IP of the client exists on that same node, the response packet is sent directly back to the client without passing through the CLB, which results in abnormal traffic and request failures.
- Create a YAML file for the Service and specify the IP mode by using an annotation. Here is an example file named service-demo.yaml :
- The following table describes the annotations.
- Run the following command to create a Service.
Confirming configurations
After the configuration is complete, you can view the details of the Service to check whether the configurations have taken effect through the status field. The status.ipMode field indicates the IP mode of the Service.
After the configuration is complete, you can view the CLB monitoring dashboard to check the traffic forwarding status.
- In the left navigation bar, click Instances. In the instance list on the right side, find the CLB instance created by VKE (typically named k8s-f040f***).
- Click the instance name to go to the instance details page. Click the Monitoring tab to view the monitoring information of the instance.
- Log in to a container in the cluster and then access the CLB address and port number. Note: This container cannot be on the same node as any back-end pod of the Service.
- Run the following command to log in to the container.
- Run the following command to access the address and port number of the CLB instance.
- The expected result is as follows: The back-end service can be accessed as expected through the IP address and port number of the CLB instance.
- Wait for a period of time and then view the monitoring data of the CLB instance.
- If the IP mode is VIP, no data about new connections is displayed in the CLB instance monitoring information. This indicates that the traffic does not pass through the CLB instance.
- If the IP mode is Proxy, data about new connections is displayed in the CLB instance monitoring information. This indicates that the traffic passes through the CLB instance and is forwarded by the CLB instance as expected.