本文介绍如何免密拉取阿里云容器镜像仓库中的私有镜像。 前提条件

您已经成功创建一个Kubernetes 集群,参见创建 Kubernetes 集群。 背景信息

免密拉取功能:

仅支持拉取当前用户阿里云容器镜像仓库中的私有镜像,无法拉取其余用户的私有镜像。

支持跨地域拉取阿里云容器镜像仓库中的私有镜像。

支持多命名空间免密拉取。

支持配置免密拉取阿里云容器镜像服务企业版中的私有镜像。

支持的集群:

专有版Kubernetes集群

托管版Kubernetes集群

Serverless Kubernetes集群

支持的版本:

专有版Kubernetes集群:高于或等于1.11.2的版本默认支持免密拉取镜像。版本低于1.11.2的版本请参考操作步骤。

托管版Kubernetes集群:所有版本。

Serverless Kubernetes集群:所有版本。

操作步骤

登录容器服务管理控制台。

在 Kubernetes 菜单下,单击左侧导航栏的集群 > 集群,进入集群列表页面。

单击目标集群的名称,查看集群的详细信息。

单击集群资源区域的Worker RAM角色,跳转到RAM访问控制台的RAM角色管理页面。

集群资源

说明

本文以新版RAM访问控制台为例进行介绍。

若您使用的是旧版的RAM访问控制台:

方法一

单击左侧导航栏角色管理,在角色名中输入Worker RAM角色的名称进行搜索。单击角色名称。角色管理

在基本信息区域,单击页面右上角的编辑基本信息。基本信息

方法二

单击页面右下角体验新版,切换到新版RAM访问控制台。在容器服务管理控制台单击Worker RAM 角色重新登录RAM访问控制台。RAM概览

在RAM角色管理页面,单击权限管理区域的权限策略名称,查看具体的权限策略。

在权限策略管理页面,单击策略内容区域的修改策略内容。

修改策略内容

在策略内容区域增加以下字段后,单击确定。

{

"Action": [

"cr:Get*",

"cr:List*",

"cr:PullRepository"

],

"Resource": "*",

"Effect": "Allow"

}

添加策略

创建aliyun-acr-credential-helper服务,定时刷新容器镜像服务的临时token密码。

apiVersion: v1

kind: ConfigMap

metadata:

name: acr-configuration

namespace: kube-system

data:

#具体配置说明参考下文

acr-api-version: "2018-12-01"

#acr-registry: "xxx-registry.*.cr.aliyuncs.com,xxx-registry-vpc.*.cr.aliyuncs.com"

#watch-namespace: "all"

#expiring-threshold: "15m"

---

apiVersion: v1

kind: ServiceAccount

metadata:

name: aliyun-acr-credential-helper

namespace: kube-system

---

apiVersion: rbac.authorization.k8s.io/v1beta1

kind: ClusterRole

metadata:

name: aliyun-acr-credential-helper

rules:

- apiGroups:

- ""

resources:

- namespaces

- configmaps

verbs:

- get

- list

- watch

- apiGroups:

- ""

resources:

- serviceaccounts

- secrets

verbs:

- create

- update

- patch

- get

- list

- watch

---

apiVersion: rbac.authorization.k8s.io/v1beta1

kind: ClusterRoleBinding

metadata:

name: aliyun-acr-credential-helper

roleRef:

apiGroup: rbac.authorization.k8s.io

kind: ClusterRole

name: aliyun-acr-credential-helper

subjects:

- kind: ServiceAccount

name: aliyun-acr-credential-helper

namespace: kube-system

---

apiVersion: apps/v1beta2

kind: Deployment

metadata:

name: aliyun-acr-credential-helper

namespace: kube-system

annotations:

component.version: "v19.05.22"

component.revision: "v1"

labels:

app: aliyun-acr-credential-helper

spec:

replicas: 1

selector:

matchLabels:

app: aliyun-acr-credential-helper

template:

metadata:

labels:

app: aliyun-acr-credential-helper

spec:

serviceAccountName: aliyun-acr-credential-helper

containers:

- name: aliyun-acr-credential-helper

image: registry.cn-hangzhou.aliyuncs.com/acs/aliyun-acr-credential-helper:v19.05.22.0-e324a5a-aliyun

imagePullPolicy: Always

env:

- name: POD_NAME

valueFrom:

fieldRef:

fieldPath: metadata.name

- name: POD_NAMESPACE

valueFrom:

fieldRef:

fieldPath: metadata.namespace

volumeMounts:

- name: localtime

mountPath: /etc/localtime

readOnly: true

volumes:

- name: localtime

hostPath:

path: /etc/localtime

type: File

nodeSelector:

beta.kubernetes.io/os: linux

ACR Credential Helper组件配置项可通过 ConfigMap 的方式来进行配置,并会自动实时生效。

表 1. 配置说明 配置项 配置项说明 默认值

acr-api-version 期望使用的CR OpenAPI Version 2018-12-01 (支持企业版Registy API)

acr-registry 期望能免密拉取镜像的Registry registry.*.aliyuncs.com,registry-vpc.*.aliyuncs.com,xxx-registry.*.cr.aliyuncs.com,xxx-registry-vpc.*.cr.aliyuncs.com

说明 如果需要配置多个Registry时,以逗号分隔。

watch-namespace 期望能免密拉取镜像的Namespace default

说明

当取值为all时,表示期望所有Namespace都能免密拉取。

如果需要配置多个Namespace时,以逗号分隔。

expiring-threshold 本地Cache Token快过期阈值 15m

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐