|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes v1.26:对跨名字空间存储数据源的 Alpha 支持" |
| 4 | +date: 2023-01-02 |
| 5 | +slug: cross-namespace-data-sources-alpha |
| 6 | +--- |
| 7 | +<!-- |
| 8 | +layout: blog |
| 9 | +title: "Kubernetes v1.26: Alpha support for cross-namespace storage data sources" |
| 10 | +date: 2023-01-02 |
| 11 | +slug: cross-namespace-data-sources-alpha |
| 12 | +--> |
| 13 | + |
| 14 | +<!-- |
| 15 | +**Author:** Takafumi Takahashi (Hitachi Vantara) |
| 16 | +--> |
| 17 | +**作者:** Takafumi Takahashi (Hitachi Vantara) |
| 18 | + |
| 19 | +**译者:** Michael Yao (DaoCloud) |
| 20 | + |
| 21 | +<!-- |
| 22 | +Kubernetes v1.26, released last month, introduced an alpha feature that |
| 23 | +lets you specify a data source for a PersistentVolumeClaim, even where the source |
| 24 | +data belong to a different namespace. |
| 25 | +With the new feature enabled, you specify a namespace in the `dataSourceRef` field of |
| 26 | +a new PersistentVolumeClaim. Once Kubernetes checks that access is OK, the new |
| 27 | +PersistentVolume can populate its data from the storage source specified in that other |
| 28 | +namespace. |
| 29 | +Before Kubernetes v1.26, provided your cluster had the `AnyVolumeDataSource` feature enabled, |
| 30 | +you could already provision new volumes from a data source in the **same** |
| 31 | +namespace. |
| 32 | +However, that only worked for the data source in the same namespace, |
| 33 | +therefore users couldn't provision a PersistentVolume with a claim |
| 34 | +in one namespace from a data source in other namespace. |
| 35 | +To solve this problem, Kubernetes v1.26 added a new alpha `namespace` field |
| 36 | +to `dataSourceRef` field in PersistentVolumeClaim the API. |
| 37 | +--> |
| 38 | +上个月发布的 Kubernetes v1.26 引入了一个 Alpha 特性,允许你在源数据属于不同的名字空间时为 |
| 39 | +PersistentVolumeClaim 指定数据源。启用这个新特性后,你在新 PersistentVolumeClaim 的 |
| 40 | +`dataSourceRef` 字段中指定名字空间。一旦 Kubernetes 发现访问权限正常,新的 PersistentVolume |
| 41 | +就可以从其他名字空间中指定的存储源填充其数据。在 Kubernetes v1.26 之前,如果集群已启用了 |
| 42 | +`AnyVolumeDataSource` 特性,你可能已经从**相同的**名字空间中的数据源制备新卷。 |
| 43 | +但这仅适用于同一名字空间中的数据源,因此用户无法基于一个名字空间中的数据源使用另一个名字空间中的声明来制备 |
| 44 | +PersistentVolume。为了解决这个问题,Kubernetes v1.26 在 PersistentVolumeClaim API 的 |
| 45 | +`dataSourceRef` 字段中添加了一个新的 Alpha `namespace` 字段。 |
| 46 | + |
| 47 | +<!-- |
| 48 | +## How it works |
| 49 | +
|
| 50 | +Once the csi-provisioner finds that a data source is specified with a `dataSourceRef` that |
| 51 | +has a non-empty namespace name, |
| 52 | +it checks all reference grants within the namespace that's specified by the`.spec.dataSourceRef.namespace` |
| 53 | +field of the PersistentVolumeClaim, in order to see if access to the data source is allowed. |
| 54 | +If any ReferenceGrant allows access, the csi-provisioner provisions a volume from the data source. |
| 55 | +--> |
| 56 | +## 工作原理 {#how-it-works} |
| 57 | + |
| 58 | +一旦 csi-provisioner 发现数据源是使用具有非空名字空间名称的 `dataSourceRef` 指定的, |
| 59 | +它就会检查由 PersistentVolumeClaim 的 `.spec.dataSourceRef.namespace` |
| 60 | +字段指定的名字空间内所授予的所有引用,以便确定可以访问数据源。 |
| 61 | +如果有 ReferenceGrant 允许访问,则 csi-provisioner 会基于数据源来制备卷。 |
| 62 | + |
| 63 | +<!-- |
| 64 | +## Trying it out |
| 65 | +
|
| 66 | +The following things are required to use cross namespace volume provisioning: |
| 67 | +
|
| 68 | +* Enable the `AnyVolumeDataSource` and `CrossNamespaceVolumeDataSource` [feature gates](/docs/reference/command-line-tools-reference/feature-gates/) for the kube-apiserver and kube-controller-manager |
| 69 | +* Install a CRD for the specific `VolumeSnapShot` controller |
| 70 | +* Install the CSI Provisioner controller and enable the `CrossNamespaceVolumeDataSource` feature gate |
| 71 | +* Install the CSI driver |
| 72 | +* Install a CRD for ReferenceGrants |
| 73 | +--> |
| 74 | +## 试用 {#trying-it-out} |
| 75 | + |
| 76 | +使用跨名字空间卷制备时以下事项是必需的: |
| 77 | + |
| 78 | +* 为 kube-apiserver 和 kube-controller-manager 启用 `AnyVolumeDataSource` 和 |
| 79 | + `CrossNamespaceVolumeDataSource` [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/) |
| 80 | +* 为特定的 `VolumeSnapShot` 控制器安装 CRD |
| 81 | +* 安装 CSI Provisioner 控制器并启用 `CrossNamespaceVolumeDataSource` 特性门控 |
| 82 | +* 安装 CSI 驱动程序 |
| 83 | +* 为 ReferenceGrants 安装 CRD |
| 84 | + |
| 85 | +<!-- |
| 86 | +## Putting it all together |
| 87 | +
|
| 88 | +To see how this works, you can install the sample and try it out. |
| 89 | +This sample do to create PVC in dev namespace from VolumeSnapshot in prod namespace. |
| 90 | +That is a simple example. For real world use, you might want to use a more complex approach. |
| 91 | +--> |
| 92 | +## 完整演练 {#putting-it-all-together} |
| 93 | + |
| 94 | +要查看其工作方式,你可以安装样例并进行试用。 |
| 95 | +此样例使用 prod 名字空间中的 VolumeSnapshot 在 dev 名字空间中创建 PVC。 |
| 96 | +这是一个简单的例子。想要在真实世界中使用,你可能要用更复杂的方法。 |
| 97 | + |
| 98 | +<!-- |
| 99 | +### Assumptions for this example {#example-assumptions} |
| 100 | +
|
| 101 | +* Your Kubernetes cluster was deployed with `AnyVolumeDataSource` and `CrossNamespaceVolumeDataSource` feature gates enabled |
| 102 | +* There are two namespaces, dev and prod |
| 103 | +* CSI driver is being deployed |
| 104 | +* There is an existing VolumeSnapshot named `new-snapshot-demo` in the _prod_ namespace |
| 105 | +* The ReferenceGrant CRD (from the Gateway API project) is already deployed |
| 106 | +--> |
| 107 | +### 这个例子的假设 {#example-assumptions} |
| 108 | + |
| 109 | +* 部署你的 Kubernetes 集群时启用 `AnyVolumeDataSource` 和 `CrossNamespaceVolumeDataSource` 特性门控 |
| 110 | +* 有两个名字空间:dev 和 prod |
| 111 | +* CSI 驱动程序被部署 |
| 112 | +* 在 **prod** 名字空间中存在一个名为 `new-snapshot-demo` 的 VolumeSnapshot |
| 113 | +* ReferenceGrant CRD(源于 Gateway API 项目)已被部署 |
| 114 | + |
| 115 | +<!-- |
| 116 | +### Grant ReferenceGrants read permission to the CSI Provisioner |
| 117 | +
|
| 118 | +Access to ReferenceGrants is only needed when the CSI driver |
| 119 | +has the `CrossNamespaceVolumeDataSource` controller capability. |
| 120 | +For this example, the external-provisioner needs **get**, **list**, and **watch** |
| 121 | +permissions for `referencegrants` (API group `gateway.networking.k8s.io`). |
| 122 | +--> |
| 123 | +### 为 CSI Provisioner 授予 ReferenceGrants 读取权限 {#grant-referencegrants-read-permission-to-csi-provisioner} |
| 124 | + |
| 125 | +仅当 CSI 驱动程序具有 `CrossNamespaceVolumeDataSource` 控制器功能时才需要访问 ReferenceGrants。 |
| 126 | +对于此示例,外部制备器对于 `referencegrants`(API 组 `gateway.networking.k8s.io`)需要 |
| 127 | +**get**、**list** 和 **watch** 权限。 |
| 128 | + |
| 129 | +```yaml |
| 130 | + - apiGroups: ["gateway.networking.k8s.io"] |
| 131 | + resources: ["referencegrants"] |
| 132 | + verbs: ["get", "list", "watch"] |
| 133 | +``` |
| 134 | +
|
| 135 | +<!-- |
| 136 | +### Enable the CrossNamespaceVolumeDataSource feature gate for the CSI Provisioner |
| 137 | +
|
| 138 | +Add `--feature-gates=CrossNamespaceVolumeDataSource=true` to the csi-provisioner command line. |
| 139 | +For example, use this manifest snippet to redefine the container: |
| 140 | +--> |
| 141 | +### 为 CSI Provisioner 启用 CrossNamespaceVolumeDataSource 特性门控 {#enable-cnvds-feature-for-csi-provisioner} |
| 142 | + |
| 143 | +将 `--feature-gates=CrossNamespaceVolumeDataSource=true` 添加到 csi-provisioner 命令行。 |
| 144 | +例如,使用此清单片段重新定义容器: |
| 145 | + |
| 146 | +```yaml |
| 147 | + - args: |
| 148 | + - -v=5 |
| 149 | + - --csi-address=/csi/csi.sock |
| 150 | + - --feature-gates=Topology=true |
| 151 | + - --feature-gates=CrossNamespaceVolumeDataSource=true |
| 152 | + image: csi-provisioner:latest |
| 153 | + imagePullPolicy: IfNotPresent |
| 154 | + name: csi-provisioner |
| 155 | +``` |
| 156 | + |
| 157 | +<!-- |
| 158 | +### Create a ReferenceGrant |
| 159 | + |
| 160 | +Here's a manifest for an example ReferenceGrant. |
| 161 | +--> |
| 162 | +### 创建 ReferenceGrant {#create-a-referencegrant} |
| 163 | + |
| 164 | +以下是 ReferenceGrant 示例的清单。 |
| 165 | + |
| 166 | +```yaml |
| 167 | +apiVersion: gateway.networking.k8s.io/v1beta1 |
| 168 | +kind: ReferenceGrant |
| 169 | +metadata: |
| 170 | + name: allow-prod-pvc |
| 171 | + namespace: prod |
| 172 | +spec: |
| 173 | + from: |
| 174 | + - group: "" |
| 175 | + kind: PersistentVolumeClaim |
| 176 | + namespace: dev |
| 177 | + to: |
| 178 | + - group: snapshot.storage.k8s.io |
| 179 | + kind: VolumeSnapshot |
| 180 | + name: new-snapshot-demo |
| 181 | +``` |
| 182 | + |
| 183 | +<!-- |
| 184 | +### Create a PersistentVolumeClaim by using cross namespace data source |
| 185 | + |
| 186 | +Kubernetes creates a PersistentVolumeClaim on dev and the CSI driver populates |
| 187 | +the PersistentVolume used on dev from snapshots on prod. |
| 188 | +--> |
| 189 | +### 通过使用跨名字空间数据源创建 PersistentVolumeClaim {#create-a-pvc-by-using-cross-ns-data-source} |
| 190 | + |
| 191 | +Kubernetes 在 dev 上创建 PersistentVolumeClaim,CSI 驱动程序从 prod 上的快照填充在 |
| 192 | +dev 上使用的 PersistentVolume。 |
| 193 | + |
| 194 | +```yaml |
| 195 | +apiVersion: v1 |
| 196 | +kind: PersistentVolumeClaim |
| 197 | +metadata: |
| 198 | + name: example-pvc |
| 199 | + namespace: dev |
| 200 | +spec: |
| 201 | + storageClassName: example |
| 202 | + accessModes: |
| 203 | + - ReadWriteOnce |
| 204 | + resources: |
| 205 | + requests: |
| 206 | + storage: 1Gi |
| 207 | + dataSourceRef: |
| 208 | + apiGroup: snapshot.storage.k8s.io |
| 209 | + kind: VolumeSnapshot |
| 210 | + name: new-snapshot-demo |
| 211 | + namespace: prod |
| 212 | + volumeMode: Filesystem |
| 213 | +``` |
| 214 | + |
| 215 | +<!-- |
| 216 | +## How can I learn more? |
| 217 | + |
| 218 | +The enhancement proposal, |
| 219 | +[Provision volumes from cross-namespace snapshots](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/3294-provision-volumes-from-cross-namespace-snapshots), includes lots of detail about the history and technical implementation of this feature. |
| 220 | + |
| 221 | +Please get involved by joining the [Kubernetes Storage Special Interest Group (SIG)](https://github.com/kubernetes/community/tree/master/sig-storage) |
| 222 | +to help us enhance this feature. |
| 223 | +There are a lot of good ideas already and we'd be thrilled to have more! |
| 224 | +--> |
| 225 | +## 怎样了解更多 {#how-can-i-learn-more} |
| 226 | + |
| 227 | +增强提案 |
| 228 | +[Provision volumes from cross-namespace snapshots](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/3294-provision-volumes-from-cross-namespace-snapshots) |
| 229 | +包含了此特性的历史和技术实现的大量细节。 |
| 230 | + |
| 231 | +若想参与,请加入 |
| 232 | +[Kubernetes 存储特别兴趣小组 (SIG)](https://github.com/kubernetes/community/tree/master/sig-storage) |
| 233 | +帮助我们增强此特性。SIG 内有许多好点子,我们很高兴能有更多! |
| 234 | + |
| 235 | +<!-- |
| 236 | +## Acknowledgments |
| 237 | + |
| 238 | +It takes a wonderful group to make wonderful software. |
| 239 | +Special thanks to the following people for the insightful reviews, |
| 240 | +thorough consideration and valuable contribution to the CrossNamespaceVolumeDataSouce feature: |
| 241 | +--> |
| 242 | +## 致谢 {#acknowledgments} |
| 243 | + |
| 244 | +制作出色的软件需要优秀的团队。 |
| 245 | +特别感谢以下人员对 CrossNamespaceVolumeDataSouce 特性的深刻见解、周密考量和宝贵贡献: |
| 246 | + |
| 247 | +* Michelle Au (msau42) |
| 248 | +* Xing Yang (xing-yang) |
| 249 | +* Masaki Kimura (mkimuram) |
| 250 | +* Tim Hockin (thockin) |
| 251 | +* Ben Swartzlander (bswartz) |
| 252 | +* Rob Scott (robscott) |
| 253 | +* John Griffith (j-griffith) |
| 254 | +* Michael Henriksen (mhenriks) |
| 255 | +* Mustafa Elbehery (Elbehery) |
| 256 | + |
| 257 | +<!-- |
| 258 | +It’s been a joy to work with y'all on this. |
| 259 | +--> |
| 260 | +很高兴与大家一起工作。 |
0 commit comments