You can use the aliyun-acr-credential-helper component to pull private images without a password from instances of Container Registry Personal Edition and Enterprise Edition in a self-managed Kubernetes cluster. This topic describes how to use aliyun-acr-credential-helper to pull a private image without a password in two scenarios.
Prerequisites
- A cluster registration proxy is created and a self-managed Kubernetes cluster is connected to the cluster registration proxy. For more information, see Create a cluster registration proxy and register an on-premises cluster.
- A kubectl client is connected to the self-managed cluster. For more information, see Connect to Kubernetes clusters by using kubectl.
Limits
aliyun-acr-credential-helper supports the following images and clusters:
- Supported images
- Supported clusters
- You can use the component to pull images without a password for clusters that contain multiple namespaces.
- The Kubernetes version of the cluster must be 1.11.2 or later. Otherwise, you must upgrade the Kubernetes version of the cluster. For more information, see Upgrade a cluster.
Precautions
- To use aliyun-acr-credential-helper, do not manually specify the imagePullSecret field. If the imagePullSecret field is specified in the template of a Kubernetes resource, such as a Deployment, the component becomes invalid.
- If a Kubernetes resource, such as a Deployment, uses custom service accounts, you must modify the service-account field in the configuration file of the component. Then, the component is authorized to pull images with the custom service accounts.
- After you create a service account in a cluster, it takes some time for aliyun-acr-credential-helper to renew the token of the service account. The new token for pulling private images is generated based on the default permissions of the ACK cluster. Applications with the service account can use the token to pull images only after the token is renewed. If you create an application immediately after you create a service account, the application will fail to pull images because it is unauthorized.
- By default, the configuration of aliyun-acr-credential-helper overwrites the imagePullSecret field of default service accounts in all namespaces. These service accounts are automatically modified when the service-account field of the acr-configuration ConfigMap in the kube-system namespace is changed.
- When you modify the acr-configuration ConfigMap in the kube-system namespace, make sure that you use the same indentation as the example in this topic. We recommend that you paste the YAML code provided in this topic to the editor, replace the corresponding values, and apply the configuration. This ensures that the format of the ConfigMap is valid.
Configure the aliyun-acr-credential-helper component in the self-managed cluster
Step 1: Configure RAM permissions for the component
Before you can install the component in an external cluster, you must set the AccessKey pair to grant the external cluster the permissions to access Alibaba Cloud resources. Before you set the AccessKey pair, create a Resource Access Management (RAM) user and grant the RAM user the permissions to access Alibaba Cloud resources.
Step 2: Upgrade and configure the component
Before you can use the component, you may need to upgrade and configure the component.
Scenario 1: Pull private images from instances of Container Registry Personal Edition and Enterprise Edition
- Pull private images from Container Registry Enterprise Edition.
data: service-account: "default" watch-namespace: "all" expiring-threshold: "15m" notify-email: "cs@aliyuncs.com" acr-registry-info: | - instanceId: "cri-xxx" regionId: "cn-hangzhou" domains: "xxx.com","yyy.com"
- Pull private images from Container Registry Personal Edition.
data: service-account: "default" watch-namespace: "all" expiring-threshold: "15m" notify-email: "cs@aliyuncs.com" acr-registry-info: | - instanceId: "" regionId: "cn-hangzhou" domains: "xxx.com","yyy.com"
- Pull private images from both Container Registry Enterprise Edition and Personal Edition.
data: service-account: "default" watch-namespace: "all" expiring-threshold: "15m" notify-email: "cs@aliyuncs.com" acr-registry-info: | - instanceId: "" - instanceId: "cri-xxxx"
Scenario 2: Pull images across regions
If you want to pull images from Container Registry instances that are deployed in different regions, you must modify the acr-configuration ConfigMap.
For example, you want to pull images from Container Registry instances that are deployed in the China (Beijing) and China (Hangzhou) regions at the same time. In this case, modify acr-configuration as shown in the following code block. For more information, see Configure the component.
data:
service-account: "default"
watch-namespace: "all"
expiring-threshold: "15m"
notify-email: "cs@aliyuncs.com"
acr-registry-info: |
- instanceId: ""
regionId: cn-beijing
- instanceId: ""
regionId: cn-hangzhou