Use p2p acceleration in ACK or ACK Serverless clusters
Use the p2p acceleration feature in Container Service for Kubernetes (ACK) and ACK Serverless clusters to speed up image pulls and reduce application deployment time. This topic describes how to use this feature in ACK and ACK Serverless clusters.
Prerequisites
You have a Standard or Advanced Container Registry Enterprise Edition instance. For more information, see Create an Enterprise Edition instance.
If you access the Container Registry Enterprise Edition instance over a VPC, ensure the instance allows access from the ACK cluster's VPC. For more information, see Configure VPC access control. If you access the instance over the internet, make sure that public access is enabled and a whitelist is configured. For more information, see Configure internet access control.
Step 1: Grant ACR read permissions
If you use an ACK Serverless cluster, you must grant the p2p component read permissions on ACR resources.
For managed or dedicated clusters, you do not need to configure these permissions as they are granted by default.
Create a RAM role.
When you create the RAM role, set Role Type to Normal Service Role and select ECS as the trusted service. For more information, see Create a service RAM role.
Configure a permission policy for the RAM role.
Attach the AliyunContainerRegistryReadOnlyAccess policy to the RAM role. For more information, see Manage permissions for a RAM role.
Step 2: Obtain the instance ID
Log on to the Container Registry console.
In the top navigation bar, select a region.
In the navigation pane on the left, click Instances.
On the Instances page, click the Enterprise Edition instance that you want to manage.
On the Overview page, find the ID of the Container Registry instance in the upper-left corner.
Step 3: Install the p2p component
Log on to the Container Service Management Console.
In the navigation pane on the left, choose .
On the App Catalog page, search for and click ack-acr-acceleration-p2p.
On the component page, click Quick Deployment.
In the Create pane, select a cluster and a namespace, and then click Next.
On the Parameters page, set the registryInstances parameter to the ID of your Container Registry instance.
If you have multiple Container Registry instances, separate their IDs with commas (,) when you set the registryInstances parameter.
NoteBy default, the p2p component uses port 65001 on nodes. If a port conflict occurs, change the port number based on your requirements.
p2p: ... # Port of P2P Agent in host network port: 65001 # ID of ACR registry instances. Multiple IDs are supported, for example, "cri-xxx,cri-yyy" registryInstances: <ACR instance Id>Optional: Set the controller.ramRole parameter to the name of your RAM role.
NoteYou are required to set the controller.ramRole parameter only for ACK Serverless clusters. You can skip this step for other clusters.
controller: ... # Setting for an ACK Serverless cluster to access ACR OpenAPI(Get*, List*) for ECS. ramRole: <your ram role name>Optional: Use the ratelimit parameter to configure the total bandwidth limit for the p2p component on a node, including download and upload bandwidth. The default value is 512 MB/s. Adjust this value based on the bandwidth of your node.
p2p: # Total net rate limit (MBytes/s) for uploading and downloading ratelimit: "512M"In the Create pane, select the cluster and then click Create.
Step 4: Enable p2p acceleration
You can enable p2p acceleration by adding a specific label to either a workload (like a Pod or Deployment) or an entire namespace. Applying the label to a namespace automatically enables acceleration for all eligible workloads within it, without needing to modify each workload's YAML file.
The label key is k8s.aliyun.com/image-accelerate-mode and the value is p2p.
Add the p2p acceleration label to a workload.
To add the label to a Deployment, run the following command to edit it:
kubectl edit deploy <deployment-name>Add the label
k8s.aliyun.com/image-accelerate-mode: p2pto the Deployment manifest.apiVersion: apps/v1 kind: Deployment metadata: name: test labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: # enable P2P k8s.aliyun.com/image-accelerate-mode: p2p app: nginx spec: # your ACR instance image pull secret imagePullSecrets: - name: test-registry containers: # your ACR instance image - image: test-registry-vpc.cn-hangzhou.cr.aliyuncs.com/docker-builder/nginx:latest name: test command: ["sleep", "3600"]Add the p2p acceleration label to a namespace.
Add the p2p acceleration label in the console.
Log on to the Container Service Management Console.
In the navigation pane on the left, click Cluster.
On the Clusters page, find the target cluster and click its name, or click Details in the Actions column.
In the left-side navigation pane of the cluster management page, click Namespaces and Quotas.
On the Namespace page, find the target namespace and click Edit in the Actions column.
In the Edit the namespace dialog box, set the Tag's Variable Key to
k8s.aliyun.com/image-accelerate-modeand the Tag's Variable Value top2p, and then click Confirm.
Add the p2p acceleration label by using kubectl.
kubectl label namespaces <your-namespace> k8s.aliyun.com/image-accelerate-mode=p2p
Verify p2p acceleration
After p2p acceleration is enabled, the p2p component automatically injects p2p-related annotations, the p2p-accelerated image address, and the corresponding imagePullSecret into the Pod.
The original and p2p-accelerated image pull credentials are identical except for the repository domain name. Therefore, if the credentials in your original imagePullSecret are incorrect, the p2p image pull will also fail.
Run the following command to view the Pod:
kubectl get po <pod-name> -oyamlExpected output:
apiVersion: v1
kind: Pod
metadata:
annotations:
# inject p2p-annotations automatically
k8s.aliyun.com/image-accelerate-mode: p2p
k8s.aliyun.com/p2p-config: '...'
spec:
containers:
# inject image to p2p endpoint
- image: test-registry-vpc.distributed.cn-hangzhou.cr.aliyuncs.com:65001/docker-builder/nginx:latest
imagePullSecrets:
- name: test-registry
# inject image pull secret for p2p endpoint
- name: acr-credential-test-registry-p2pThe output confirms that the p2p-related annotations, the p2p-accelerated image address, and the corresponding imagePullSecret have been injected into the Pod, which means p2p acceleration is enabled.