大家好,我是张晋涛。
Kubernetes v1.26 是 2022 年的最后一个大版本更新,包含了 37 项主要的更新。
8 月底正式发布的 v1.25 中包含 40 项,单从这个角度来看,Kubernetes 每个版本节奏的把控也是挺不错的。
我每期的 「k8s生态周报」都有一个叫上游进展的部分,所以很多值得关注的内容在之前的文章中已经发过了。这篇中我会再额外介绍一些之前未涵盖的,和之前介绍过的值得关注的内容。
在 v1.26 中包含了很多直接影响用户与 Kubernetes 交互相关的功能,比如以下内容中会介绍的允许跨 namespace 持久化卷快照引用;允许用户无需额外的 exporter 即可自定义 Service Level Indicator(SLI); kubectl events 达到 Beta;支持 Pod 所需资源就绪后再进行调度;支持使用 OpenAPI v3 等。
以及针对高性能负载运行在哪个物理 CPU 的场景支持。
我们一起来具体看看吧!
#3294 允许跨 namespace 持久化卷快照引用
在 Kubernetes 中,用户可以通过使用 VolumeSnapshot
特性,从卷快照创建新的持久化卷。这是非常有用的,比如说 DBA 可以在进行数据库大的变更/迁移操作前,对持久化卷做一次快照,如果出现异常,则可以直接从该快照恢复数据库之前的状态。
例如通过以下方式可以动态的创建一个快照:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: test-snapclass
driver: testdriver.csi.k8s.io
deletionPolicy: Delete
parameters:
csi.storage.k8s.io/snapshotter-secret-name: mysecret
csi.storage.k8s.io/snapshotter-secret-namespace: mysecretnamespace
---
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: test-snapshot
namespace: ns1
spec:
volumeSnapshotClassName: test-snapclass
source:
persistentVolumeClaimName: test-pvc
当然,这里也有些需要注意的点,该功能只能用于 CSI 存储驱动,并且该功能是自 Kubernetes v1.17 达到 beta,v1.20 正式 GA 的。
在 v1.26 中增加的特性是 CrossNamespaceVolumeDataSource
当前是 Alpha 阶段,允许创建持久化卷的时候,跨 namespace 引用卷快照。它的主要价值在于,比如想要做应用跨 namespace 迁移的时候,直接从另一个 namespace 对持久化卷做快照,然后使用快照创建 PVC 即可很轻松的完成迁移。例如:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: testvolumeclaim
namespace: nstest1
spec:
storageClassName: mystorageclass
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
dataSourceRef:
apiGroup: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: testsnapshot
namespace: moelove
volumeMode: Filesystem
当然如果考虑授权相关问题的话,这里使用 Gateway API 的 ReferenceGrant 来控制授权。
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: ReferenceGrant
metadata:
name: test
namespace: moelove
spec:
from:
- group: ""
kind: PersistentVolumeClaim
namespace: nstest1
to:
- group: snapshot.storage.k8s.io
kind: VolumeSnapshot
name: testsnapshot
我认为这是个很实用的功能。
#3488 允许使用 CEL 进行 Admission Control
我在去年的 K8S 生态周报| Kubernetes v1.23.0 正式发布,新特性一览 | MoeLove 文章中,曾介绍过 Kubernetes 中引入了 Common Expression Language (CEL) 进行 CRD Validation。该特性在 v1.25 达到 Beta。
例如,某个 CRDs 的内容如下,其中定义了 minReplicas
小于 replicas
并且 replicas
小于 maxReplicas
。
...
openAPIV3Schema:
type: object
properties:
spec:
type: object
x-kubernetes-validation-rules:
- rule: "self.minReplicas <= self.replicas"
message: "replicas should be greater than or equal to minReplicas."
- rule: "self.replicas <= self.maxReplicas"
message: "replicas should be smaller than or equal to maxReplicas."
properties:
...
minReplicas:
type: integer
replicas:
type: integer
maxReplicas:
type: integer
required:
- minReplicas
- replicas
- maxReplicas
<