包阅导读总结
1. `Kubernetes 1.31`、`OCI Artifacts`、`Read Only Volumes`、`Image Volume Source`、`Use Cases`
2. Kubernetes 1.31 引入新的 alpha 特性——基于 OCI 制品的只读卷(Image Volume Source),旨在满足更多 AI/ML 等用例需求,文中介绍了其使用示例、用例和一些实现细节。
3.
– Kubernetes 正迎合 AI/ML 需求引入新特性
– 支持 OCI 兼容图像和制品作为原生卷源
– 推出新的 alpha 特性 Image Volume Source(KEP-4639)
– 用例
– 多容器共享配置文件,减小安全风险和镜像大小
– 分发二进制制品,优化 CI/CD 流程
– 数据科学家等挂载模型权重
– 安全工程师使用公共镜像加载私有恶意软件签名
– 详细示例
– 启用相关特性门控
– 介绍 pullPolicy 等行为
– 展示创建 pod 及操作结果
– 说明实现细节,如卷只读等
思维导图:
文章地址:https://kubernetes.io/blog/2024/08/16/kubernetes-1-31-image-volume-source/
文章来源:kubernetes.io
作者:Kubernetes Blog
发布时间:2024/8/16 0:00
语言:英文
总字数:1060字
预计阅读时间:5分钟
评分:87分
标签:Kubernetes,OCI 对象,卷管理,容器化,CI/CD
以下为原文内容
本内容来源于用户推荐转载,旨在分享知识与观点,如有侵权请联系删除 联系邮箱 media@ilingban.com
Kubernetes 1.31: Read Only Volumes Based On OCI Artifacts (alpha)
By Sascha Grunert |
The Kubernetes community is moving towards fulfilling more ArtificialIntelligence (AI) and Machine Learning (ML) use cases in the future. While theproject has been designed to fulfill microservice architectures in the past,it’s now time to listen to the end users and introduce features which have astronger focus on AI/ML.
One of these requirements is to support Open Container Initiative (OCI)compatible images and artifacts (referred as OCI objects) directly as a nativevolume source. This allows users to focus on OCI standards as well as enablesthem to store and distribute any content using OCI registries. A feature likethis gives the Kubernetes project a chance to grow into use cases which gobeyond running particular images.
Given that, the Kubernetes community is proud to present a new alpha featureintroduced in v1.31: The Image Volume Source(KEP-4639). This feature allows users to specify animage reference as volume in a pod while reusing it as volume mount withincontainers:
…kind: Podspec: containers: - … volumeMounts: - name: my-volume mountPath: /path/to/directory volumes: - name: my-volume image: reference: my-image:tag
The above example would result in mounting my-image:tag
to/path/to/directory
in the pod’s container.
Use cases
The goal of this enhancement is to stick as close as possible to the existingcontainer image implementation within thekubelet, while introducing a new API surface to allow more extended use cases.
For example, users could share a configuration file among multiple containers ina pod without including the file in the main image, so that they can minimizesecurity risks and the overall image size. They can also package and distributebinary artifacts using OCI images and mount them directly into Kubernetes pods,so that they can streamline their CI/CD pipeline as an example.
Data scientists, MLOps engineers, or AI developers, can mount large languagemodel weights or machine learning model weights in a pod alongside amodel-server, so that they can efficiently serve them without including them inthe model-server container image. They can package these in an OCI object totake advantage of OCI distribution and ensure efficient model deployment. Thisallows them to separate the model specifications/content from the executablesthat process them.
Another use case is that security engineers can use a public image for a malwarescanner and mount in a volume of private (commercial) malware signatures, sothat they can load those signatures without baking their own combined image(which might not be allowed by the copyright on the public image). Those fileswork regardless of the OS or version of the scanner software.
But in the long term it will be up to you as an end user of this project tooutline further important use cases for the new feature.SIG Nodeis happy to retrieve any feedback or suggestions for further enhancements toallow more advanced usage scenarios. Feel free to provide feedback by eitherusing the Kubernetes Slack (#sig-node)channel or the SIG Node mailinglist.
Detailed example
The Kubernetes alpha feature gate ImageVolume
needs to be enabled on the API Serveras well as the kubeletto make it functional. If that’s the case and the container runtimehas support for the feature (like CRI-O ≥ v1.31), then an example pod.yaml
like this can be created:
apiVersion: v1kind: Podmetadata: name: podspec: containers: - name: test image: registry.k8s.io/e2e-test-images/echoserver:2.3 volumeMounts: - name: volume mountPath: /volume volumes: - name: volume image: reference: quay.io/crio/artifact:v1 pullPolicy: IfNotPresent
The pod declares a new volume using the image.reference
ofquay.io/crio/artifact:v1
, which refers to an OCI object containing two files.The pullPolicy
behaves in the same way as for container images and allows thefollowing values:
Always
: the kubelet always attempts to pull the reference and the containercreation will fail if the pull fails.Never
: the kubelet never pulls the reference and only uses a local image orartifact. The container creation will fail if the reference isn’t present.IfNotPresent
: the kubelet pulls if the reference isn’t already present ondisk. The container creation will fail if the reference isn’t present and thepull fails.
The volumeMounts
field is indicating that the container with the name test
should mount the volume under the path /volume
.
If you now create the pod:
kubectl apply -f pod.yaml
And exec into it:
kubectl exec -it pod -- sh
Then you’re able to investigate what has been mounted:
/ # ls /volumedir file/ # cat /volume/file2/ # ls /volume/dirfile/ # cat /volume/dir/file1
You managed to consume an OCI artifact using Kubernetes!
The container runtime pulls the image (or artifact), mounts it to thecontainer and makes it finally available for direct usage. There are a bunch ofdetails in the implementation, which closely align to the existing image pullbehavior of the kubelet. For example:
- If a
:latest
tag asreference
is provided, then thepullPolicy
willdefault toAlways
, while in any other case it will default toIfNotPresent
if unset. - The volume gets re-resolved if the pod gets deleted and recreated, which meansthat new remote content will become available on pod recreation. A failure toresolve or pull the image during pod startup will block containers fromstarting and may add significant latency. Failures will be retried usingnormal volume backoff and will be reported on the pod reason and message.
- Pull secrets will be assembled in the same way as for the container image bylooking up node credentials, service account image pull secrets, and pod specimage pull secrets.
- The OCI object gets mounted in a single directory by merging the manifestlayers in the same way as for container images.
- The volume is mounted as read-only (
ro
) and non-executable files(noexec
). - Sub-path mounts for containers are not supported(
spec.containers[*].volumeMounts.subpath
). - The field
spec.securityContext.fsGroupChangePolicy
has no effect on thisvolume type. - The feature will also work with the
AlwaysPullImages
admission pluginif enabled.
Thank you for reading through the end of this blog post! SIG Node is proud andhappy to deliver this feature as part of Kubernetes v1.31.
As writer of this blog post, I would like to emphasize my special thanks toall involved individuals out there! You all rock, let’s keep on hacking!