Report this

What is the reason for this report?

terraform failed to expose kubernetes service

Posted on September 28, 2020

I have a kub deployment to expose as LoadBalancer. Created with Terraform, looks good. But when I create a service to expose, it returns empty response all the time.

resource "kubernetes_service" "front" {
  metadata {
    name = "front"
  }
  spec {
    selector = {
      App = "front"
    }
    port {
      port = 8000
    }
    type = "LoadBalancer"
  }
}

Checked cluster status and found the service endpoint was not created by some reason.

If I delete the service with kubectl and re-create it as:

–kubeconfig ~/.kube/my-doks-config.yaml expose deployment front --type LoadBalancer

Everything is fine, endpoint created, the service exposed and working as expected.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

I am not a terraform user so I may not be the most helpful here.

Can you verify whether there are any error logs during this? Either to stdout or to a log file somewhere for terraform?

Does this issue only aoccur with an LB service? Are you able to create any kind of service?

perhaps try and see if the “nginx” example here works from the terraform docs: https://learn.hashicorp.com/tutorials/terraform/kubernetes-provider?in=terraform/kubernetes

That should give you an idea if the provider you are using is having an issue or if its your configuration of your service.

Hope this helps!

John Kwiatkoski

No errors found, except the missed endpoint. The issue occurs with both LB and ClusterIp, when I tried to expose the service via ingress.

“Nginx” example is NodePort, it was working, but it is too basic. The provider - DO Managed Kubernetes. So I gave up with TF and returned to kubectl - everything works correctly.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.