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 13, 2020 in Terraform by MD
• 95,060 points
77 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 13, 2020 by akhtar
• 38,170 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 13, 2020 in Terraform by MD
• 95,060 points
401 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 12, 2020 in Terraform by MD
• 95,060 points
263 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 12, 2020 in Terraform by MD
• 95,060 points
251 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 27, 2020 in Terraform by MD
• 95,060 points
409 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
9,916 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 11, 2019 in Kubernetes by Kalgi
• 52,310 points

reshown Apr 12, 2019 by Kalgi 3,017 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 27, 2020 in Terraform by akhtar
• 38,170 points
104 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 16, 2020 in Terraform by akhtar
• 38,170 points
158 views