terraform failed to expose kubernetes service

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.


Submit an 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.

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.

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:

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