This topic describes how to enable the Pod fail‑fast capability in VCI scenarios through a failure handling policy. When a VCI instance fails to be created due to insufficient inventory, unavailable instance types, or other reasons, the system promptly returns a failure result with a clear identifier. This helps you detect the issue in time and switch to a fallback plan (such as switching from instance family A to instance family B), preventing prolonged, ineffective waiting.
By default, when a VCI Pod fails to be created, the system automatically retries using a backoff algorithm and keeps attempting until the instance is created. This is applicable to scenarios that are sensitive to success rates and can tolerate temporary resource shortages. However, in scenarios with scarce resources such as GPUs, this mechanism causes Pods to remain in the Pending state for an extended period with repeated retries. This requires you to wait 2 to 5 minutes before confirming the failure, which does not meet the requirements of actual business scenarios.
To address this issue, VCI provides a failure handling policy (Fail‑strategy) that allows you to declare fail‑fast behavior on Pods. When resource creation tasks fail, the system no longer retries for a long time. Instead, it quickly determines the failure and exposes a clear failure reason, reducing the failure confirmation time from minutes to seconds.
You can enable the Pod fail‑fast capability by adding an annotation to the target Pod. The following table describes the core annotation.
Take note of the following limits when you use the VCI Pod fail-fast capability.
- A fallback solution has been prepared to enable timely switching after a fast failure. For an example of how to switch to a fallback solution, see the Switch to a fallback solution section of this topic.
The following example uses a Deployment with the general-purpose instance type vci.n3a.4c-8gi. By pinning the Pod subnet to the cn-beijing-a availability zone, it simulates a scenario where the vci.n3a instance type is out of stock in the zone, thereby validating the result when fail-fast is enabled. For VCI instance types supported in each region and availability zone, see Regions and availability zones. For instructions on configuring VCI Pod subnets, see Managing virtual nodes. Step 1: Declare a fail-fast policy in a workload
Enable fail-fast in the workload via a Pod annotation.
- Create a YAML file for the Deployment. The following vci-failfast-demo.yaml file provides a code sample.
- Run the following command to create a Deployment.
Step 2: Verify whether fail-fast takes effect
After fail‑fast is enabled, the Pod does not immediately become Failed. Instead, its status.phase remains Pending, status.reason is set to CreatePodError, the status.message provides the specific failure reason, and the container remains in the ContainerCreating state.
- Run the following command to obtain the name of the Pod in the Deployment.
- The expected output is as follows:
- Run the following command to view the status field of the Pod.
- The expected result is as follows (excerpt of the status section):
Step 3: (Optional) Switch to a fallback solution
Upper‑layer workloads or O&M processes can trigger switching logic based on the fail‑fast identifier. For example, when GPUs are out of stock, you can submit a workload with large-core CPU specifications to continue the computation. The following content provides two solutions. You can adopt other solutions based on your business requirements.
Solution 1 (recommended)
Solution 2
Make sure that the business workload is created and runs as expected by appending fallback instance types within the same workload.
The VCI annotations for specifying instance types or families (such as preferred-instance-types) support multiple values separated by commas, ordered by priority. When a higher‑priority instance type is unavailable, the system uses a lower‑priority type or family to create the instance.
tip
This solution shifts the switching operation forward to the creation stage. The majority of inventory fluctuations are automatically covered by a fallback mechanism without requiring manual intervention, and the fail-fast mode is triggered only when all candidate instance types are unavailable.
After a fail‑fast event, switch to another instance type and recreate the Pod to ensure that the business workload is created and runs as expected.
When all candidate instance types are out of stock and the Pod has exposed CreatePodError, modify the instance type annotation in the workload to switch to a new fallback instance type and trigger a rolling update to recreate the Pod.
- Switch to the fallback instance type. The following command switches the instance type from vci.n3a.4c-8gi to the fallback instance type vci.u1.4c-8gi.
- The expected output is as follows:
- Run the following command to observe the progress of the rolling update.
- The expected output is as follows:
- Run the following command to confirm the new Pod is running as expected.
- The expected output is as follows:
tip
For Solution 2, you can implement an automated process where a custom controller or O&M script continuously watches the status.reason of the Pod. If CreatePodError is detected, it automatically performs the preceding patch and recreation operations based on a predefined list of fallback instance types. This achieves quick switching without manual intervention.