terraform kubernetes-alpha提供程序因415不支持的媒体类型而失败

时间:2020-08-27 22:32:16

标签: kubernetes terraform terraform-provider-kubernetes

我正在尝试在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配置如下所示。

provider.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不支持

[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 manually installed plugin fails

的说明手动安装了插件

我缺少任何配置吗?

预先感谢

1 个答案:

答案 0 :(得分:0)

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