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
579 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,598 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,380 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,637 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,633 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,309 views
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,360 points

reshown Apr 12, 2019 by Kalgi 6,930 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
749 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
924 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