-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes.tf
93 lines (81 loc) · 1.85 KB
/
kubernetes.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#data "terraform_remote_state" "eks" {
# backend = "local"
# config = {
# path = "../learn-terraform-provision-eks-cluster/terraform.tfstate"
# }
#}
data "aws_eks_cluster" "cluster" {
# name = data.terraform_remote_state.eks.outputs.cluster_id
name = aws_eks_cluster.demo.name
}
provider "kubernetes" {
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
command = "aws"
args = [
"eks",
"get-token",
"--cluster-name",
data.aws_eks_cluster.cluster.name
]
}
}
resource "kubernetes_deployment" "springboot" {
metadata {
name = "scalable-springboot-example"
labels = {
App = "ScalableSpringBootExample"
}
}
spec {
replicas = 2
selector {
match_labels = {
App = "ScalableSpringBootExample"
}
}
template {
metadata {
labels = {
App = "ScalableSpringBootExample"
}
}
spec {
container {
image = "${var.AWS_ACCOUNT_ID}.dkr.ecr.${var.aws_region}.amazonaws.com/${var.REPO_NAME}:latest"
name = "springboot"
port {
container_port = 80
}
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
}
}
}
}
}
resource "kubernetes_service" "springboot" {
metadata {
name = "springboot-example"
}
spec {
selector = {
App = kubernetes_deployment.springboot.spec.0.template.0.metadata[0].labels.App
}
port {
port = 80
target_port = 80
}
type = "LoadBalancer"
}
}