【问题标题】:deploymentRes for a pvc using the dynamic-create使用动态创建的 pvc 的 deploymentRes
【发布时间】:2021-01-27 03:18:52
【问题描述】:

我正在尝试使用 client-go 在我的集群上创建 pod 和其他资源。

据我了解,使用 client-go 在集群上创建内容的最佳方法是使用动态创建版本(在示例中有一个动态创建更新删除示例)。因为我可以把我的 yaml 变成 unstructured.Unstructured 然后创建资源。

这对我来说在使用 kind: Deployment 创建 pod 时工作正常,但是当我尝试使用 kind: PersistentVolumeClaim 创建 pod 时出现错误:

恐慌:版本“v1”中的 PersistentVolumeClaim 不能作为部署处理:将 (v1.PersistentVolumeClaim).v1.PersistentVolumeClaimSpec 转换为 (apps.Deployment).apps.DeploymentSpec:副本不存在于 src 中

如果我正确理解错误,会发生这种情况,因为我使用 resource: "deployments" 声明了我的 deploymentRes

deploymentRes := schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}

然后使用:

client.Resource(deploymentRes).Namespace(namespace).Create(context.TODO(), deployment, metav1.CreateOptions{})

这里的问题是,当我想创建 pvc 时,我找不到要放置的内容而不是 Resource: "deployments"。我试图输入persistentvolumeclaim,但得到了错误:

“恐慌:服务器找不到请求的资源”

如果您知道任何可以提供帮助的信息,或者将我引向正确的方向,将会非常有帮助!

谢谢!

【问题讨论】:

    标签: go kubernetes yaml client-go


    【解决方案1】:

    这里的问题是,当我想创建 pvc 时,我找不到放什么而不是 Resource: "deployments"

    你的假设是正确的。你只漏了两点:

    • Group 参数应为 ""(空字符串)
    • Resource 参数应为 "persistentvolumeclaims"(复数形式)
    pvcRes := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolumeclaims"}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      相关资源
      最近更新 更多