Create service in Kubernetes cluster using Terraform

0 votes

Hi Guys,

I have configured one pod in the Kubernetes cluster using Terraform code. Now I want to expose the pod using Terraform. How can I do that?

Sep 14, 2020 in Terraform by MD
• 95,460 points
617 views

1 answer to this question.

0 votes

Hi@MD,

To expose the pod to end-users, provision a service. Service is capable of provisioning a load-balancer in some cloud providers. It can manage the relationship between pods and the load balancer while new pods are launched. You can see the below example.

resource "kubernetes_service" "echo" {
  metadata {
    name = "echo-example"
  }
  spec {
    selector {
      App = "${kubernetes_pod.echo.metadata.0.labels.App}"
    }
    port {
      port        = 80
      target_port = 80
    }
    type = "LoadBalancer"
} }

output "lb_ip" {
  value = "${kubernetes_service.echo.load_balancer_ingress.0.ip}"
}
answered Sep 14, 2020 by akhtar
• 38,260 points

Related Questions In Terraform

0 votes
1 answer

How to create a namespace in the Kubernetes cluster using Terraform?

Hi@akhtar, You can use kubernetes_namespace resource in your ...READ MORE

answered Sep 14, 2020 in Terraform by MD
• 95,460 points
8,679 views
0 votes
1 answer

How to create a service account in GCP using Terraform?

Hi@akhtar, You can create a service account in ...READ MORE

answered Sep 13, 2020 in Terraform by MD
• 95,460 points
2,431 views
0 votes
1 answer

How to create a service account key in GCP Cloud using Terraform?

Hi@akhtar, You need to create a service account ...READ MORE

answered Sep 13, 2020 in Terraform by MD
• 95,460 points
1,676 views
0 votes
1 answer

Create a secret in Kubernetes using Terraform.

Hi@akhtar, Terraform has resource to create a secret ...READ MORE

answered Sep 28, 2020 in Terraform by MD
• 95,460 points
2,670 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,476 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,035 views
0 votes
1 answer

How to expose a Pod in Kubernetes using Terraform?

Hi@MD, You can use kubernetes_service resource to expose ...READ MORE

answered Sep 28, 2020 in Terraform by akhtar
• 38,260 points
808 views
+2 votes
1 answer

How to create a workspace in terraform?

Hi@MD, Terraform has a command named terraform workspace. ...READ MORE

answered Aug 17, 2020 in Terraform by akhtar
• 38,260 points
999 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP