Terraform-provider-kubernetes: Error: Failed to update service: Service "app" is invalid: spec.ports[0].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'

Created on 1 Sep 2020  ·  1Comment  ·  Source: hashicorp/terraform-provider-kubernetes

Terraform Version and Provider Version

❯ terraform -v
Terraform v0.13.1
+ provider registry.terraform.io/digitalocean/digitalocean v1.22.2
+ provider registry.terraform.io/hashicorp/kubernetes v1.12.0

Affected Resource(s)

  • kubernetes_service

Terraform Configuration Files

resource "kubernetes_service" "app" {
  metadata {
    name = "app"
    namespace = kubernetes_namespace.app.metadata.0.name
  }
  spec {
    selector = {
      app = kubernetes_deployment.app.metadata.0.labels.app
    }
#    session_affinity = "ClientIP" # << This has no effect on the error
    port {
      port        = 80
      target_port = 8000
    }

#    type = "LoadBalancer" # << Error message appears when this is commented, everything is fine if it is set
  }
}

Expected Behavior

Terraform either applies the configuration or outputs a helpful error message that provides suggestions on what is causing the problem and how to fix it.

Actual Behavior

Terraform complains:

Error: Failed to update service: Service "app" is invalid: spec.ports[0].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'

Steps to Reproduce

  1. terraform apply

Important Factoids

Cluster is set up using the DigitalOcean provider.

References

There is a StackOverflow question by someone else, asking about the same problem: https://stackoverflow.com/questions/59461825/how-to-define-a-kubernetes-service-with-terraform-and-clusterip

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
bug

Most helpful comment

I had to manually set spec.port.node_port=0 and terraform apply once. That worked around the problem permanently, even after removing the node_port setting again.

>All comments

I had to manually set spec.port.node_port=0 and terraform apply once. That worked around the problem permanently, even after removing the node_port setting again.

Was this page helpful?
0 / 5 - 0 ratings