概述
artifact-streaming
今天再来分享一个目前在Global还在preview的功能,通过为AKS和ACR(Azure container registries)启用流式处理(artifact-streaming)来加速容器的部署,这个功能在一些高性能计算的场景会很有用,尤其是当image非常大,导致container部署时间很长时尤其有效
通过 AKS 上的项目流式处理功能,可将容器映像从 Azure 容器注册表 (ACR) 流式传输到 AKS。 AKS 只拉取初始 Pod 启动所需的层,从而缩短拉取映像和部署工作负载所需的时间。
项目流式处理可将 Pod 就绪时间减少 15% 以上(具体取决于映像的大小),并且最适合<30 GB 的映像。测试显示,<10 GB 的映像的 Pod 启动时间从数分钟缩短到了数秒
总体来说,就是可以让容器部署效率更高,不过目前这个功能还是preview的状态
限制
目前来说,这项功能还存在以下这些限制
- 预览版仅支持采用 Linux AMD64 体系结构的映像。
- 预览版不支持基于 Windows 的容器映像和 ARM64 映像。
- 预览版部分支持多体系结构映像,仅支持 AMD64 体系结构。
- 若要在 AKS 中创建基于 Ubuntu 的节点池,请选择 Ubuntu 版本 20.04 或更高版本。
- 对于 Kubernetes,请使用 Kubernetes 版本 1.26 或更高版本或 Kubernetes 版本 > 1.25。
- 只有高级 SKU 注册表支持在预览版本中生成流式处理项目。 非高级 SKU 注册表在预览期间不提供此功能。
- 预览版不支持 CMK(客户管理的密钥)注册表。
- 目前不支持 Kubernetes regcred。
配置
下边来看一下具体的配置过程,这次演示的是端到端的流程,包括从最开始部署ACR,build image,到最后部署container的整个流程
创建ACR和AKS
创建resource group
az group create --name Streaming `
--location eastasia
创建ACR
az acr create --resource-group Streaming `
--name streamingacr2024 `
--sku Premium
创建AKS
$subnet_id=az network vnet subnet show -g Work --vnet-name work-vnet --name default --query id -o tsv
az aks create -g Streaming `
-n StreamingAKS `
--node-osdisk-size 128 `
--admin-username azureuser `
--kubernetes-version 1.27.7 `
--location eastasia `
--network-plugin azure `
--node-count 1 `
--node-vm-size Standard_D2S_v3 `
--nodepool-name nodepool `
--service-cidr 10.10.0.0/24 `
--dns-service-ip 10.10.0.10 `
--vnet-subnet-id $subnet_id `
--load-balancer-sku Standard `
--max-pods 30
构建image
ACR和AKS部署好之后,首先登录到ACR,尝试构建一个container image,之后将image推送到ACR中,用于后续的部署
登录ACR
az acr login -n streamingacr2024
制作docker file,然后使用dockerfile构建image,首先先把用到的项目文件从GitHub拉下来
git clone https://github.com/MicrosoftDocs/pipelines-dotnet-core.git
Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /code
COPY pipelines-dotnet-core/ /code
EXPOSE 80
RUN dotnet build /code/pipelines-dotnet-core.csproj -c Release -o /release
ENTRYPOINT ["dotnet","/release/pipelines-dotnet-core.dll"]
构建image
docker build -t streamingacr2024.azurecr.io/streaming:v1.0 .
尝试在本地run下看看有没有问题
sudo docker run --name tc -d streamingacr2024.azurecr.io/streaming:v1.0
确定没问题就可以push到ACR了
sudo docker push streamingacr2024.azurecr.io/streaming:v1.0
Attach ACR
接下来就可以开始准备启用artifact-streaming了,不过在这之前,可以先把ACR attach到AKS,让AKS有权限可以从ACR 拉取镜像
$acr_id=az acr show -g Streaming -n streamingacr2024 --query id -o tsv
az aks update -n StreamingAKS -g Streaming --attach-acr $acr_id
本质上其实就是给AKS的identity一个ACR Pull的权限
开启artifact-streaming
接下来准备开启artifact-streaming,因为这是个预览版的功能,所以需要先注册
az feature register --namespace Microsoft.ContainerService --name ArtifactStreamingPreview
az provider register -n Microsoft.ContainerService
首先给ACR开启artifact-streaming
az acr artifact-streaming create --image streaming:v1.0 --name streamingacr2024
az acr manifest list-referrers -n streaming:v1.0 -r streamingacr2024
接下来给AKS的nodepool开启artifact-streaming支持
az aks nodepool update --resource-group Streaming `
--cluster-name StreamingAKS `
--name nodepool `
--enable-artifact-streaming
验证下是否启用成功
az aks nodepool show --resource-group Streaming `
--cluster-name StreamingAKS `
--name nodepool `
--query artifactStreamingProfile
最后就可以开始部署了
apiVersion: apps/v1
kind: Deployment
metadata:
name: aks-helloworld
spec:
replicas: 1
selector:
matchLabels:
app: aks-helloworld
template:
metadata:
labels:
app: aks-helloworld
spec:
containers:
- name: aks-helloworld
image: streamingacr2024.azurecr.io/streaming:v1.0
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: aks-helloworld
spec:
type: ClusterIP
ports:
- port: 80
selector:
app: aks-helloworld
可以看下部署的log
kubectl describe po aks-helloworld-79df4f469b-62p6c