0

我正在尝试在我的 terraform 配置中使用 kubernetes-alpha 提供程序。我正在使用它来应用 app-crd.yaml 将我的资源作为一个组来管理。

kubectl apply -f "https://raw.githubusercontent.com/GoogleCloudPlatform/marketplace-k8s-app-tools/master/crd/app-crd.yaml"

我使用https://github.com/jrhouston/tfk8s工具将此 yaml 文件转换为 tf 文件

我正在使用 kubernetes-alpha 提供程序将此 tf 文件作为清单应用

我的 tf 配置如下所示。

提供者.tf

terraform {
  required_providers {
    kubernetes-alpha = {
      source = "localdomain/provider/kubernetes-alpha"
    }
  }
}

provider "kubernetes-alpha" {
  host                   = "https://${var.endpoint}"
  token                  = var.token
  cluster_ca_certificate = var.cluster_ca_certificate
  server_side_planning   = true
}

app_crd.tf

resource "kubernetes_manifest" "customresourcedefinition_applications_app_k8s_io" {
  provider = kubernetes-alpha

  manifest = {
    "apiVersion" = "apiextensions.k8s.io/v1beta1"
    "kind"       = "CustomResourceDefinition"
    "metadata" = {
      "creationTimestamp" = null
      "labels" = {
        "controller-tools.k8s.io" = "1.0"
      }
      "name" = "applications.app.k8s.io"
    }
    "spec" = {
      "group" = "app.k8s.io"
      "names" = {
        "kind"   = "Application"
        "plural" = "applications"
.
.
.
    "status" = {
      "acceptedNames" = {
        "kind"   = ""
        "plural" = ""
      }
      "conditions"     = []
      "storedVersions" = []
    }
  }
}

当我尝试 terraform 计划时,我得到 415 Unsupported

[DEBUG] plugin.terraform-provider-kubernetes-alpha: -----------------------------------------------------
[DEBUG] plugin.terraform-provider-kubernetes-alpha: 2020/08/27 15:14:57 [DEBUG] Kubernetes API Response Details:
[DEBUG] plugin.terraform-provider-kubernetes-alpha: ---[ RESPONSE ]--------------------------------------
[DEBUG] plugin.terraform-provider-kubernetes-alpha: HTTP/2.0 415 Unsupported Media Type
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Content-Length: 165
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Audit-Id: 537f3df0-f9b8-4f57-a3ce-6afacc383bc4
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Content-Type: application/json
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Date: Thu, 27 Aug 2020 22:14:57 GMT
[DEBUG] plugin.terraform-provider-kubernetes-alpha:
[DEBUG] plugin.terraform-provider-kubernetes-alpha: {
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "kind": "Status",
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "apiVersion": "v1",
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "metadata": {},
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "status": "Failure",
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "message": "415: Unsupported Media Type",
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "reason": "UnsupportedMediaType",
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "details": {},
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "code": 415
[DEBUG] plugin.terraform-provider-kubernetes-alpha: }

API 请求如下所示

[DEBUG] plugin.terraform-provider-kubernetes-alpha: -----------------------------------------------------
[DEBUG] plugin.terraform-provider-kubernetes-alpha: 2020/08/27 15:14:57 [DEBUG] Kubernetes API Request Details:
[DEBUG] plugin.terraform-provider-kubernetes-alpha: ---[ REQUEST ]---------------------------------------
[DEBUG] plugin.terraform-provider-kubernetes-alpha: PATCH /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/app
lications.app.k8s.io?dryRun=All&fieldManager=Terraform HTTP/1.1
plugin.terraform-provider-kubernetes-alpha: Host: <REDACTED>
[DEBUG] plugin.terraform-provider-kubernetes-alpha: User-Agent: terraform-provider-kubernetes-alpha/v0.0.0 (darwin/amd64)
kubernetes/$Format
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Content-Length: 2957
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Accept: application/json
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Authorization: Bearer <REDACTED>
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Content-Type: application/apply-patch+yaml
[DEBUG] plugin.terraform-provider-kubernetes-alpha: Accept-Encoding: gzip
[DEBUG] plugin.terraform-provider-kubernetes-alpha:
[DEBUG] plugin.terraform-provider-kubernetes-alpha: {
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "apiVersion": "apiextensions.k8s.io/v1beta1",
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "kind": "CustomResourceDefinition",
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  "metadata": {
[DEBUG] plugin.terraform-provider-kubernetes-alpha:   "creationTimestamp": null,
[DEBUG] plugin.terraform-provider-kubernetes-alpha:   "labels": {
[DEBUG] plugin.terraform-provider-kubernetes-alpha:    "controller-tools.k8s.io": "1.0"
[DEBUG] plugin.terraform-provider-kubernetes-alpha:   },
[DEBUG] plugin.terraform-provider-kubernetes-alpha:   "name": "applications.app.k8s.io"
[DEBUG] plugin.terraform-provider-kubernetes-alpha:  },
.
.
.

我手动安装了插件,如此处所述terraform 手动安装插件失败

我是否缺少任何配置?

提前致谢

4

1 回答 1

0

我在没有服务器端支持的 1.15 版本的 GKE 集群上运行。将我的集群升级到 1.6 解决了这个问题

于 2020-08-28T19:29:42.357 回答