-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge_lab_1.tf
99 lines (76 loc) · 1.52 KB
/
challenge_lab_1.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
94
95
96
97
98
99
KodeKloud : Terraform challenge 1
----------------------
1. Terraform 1.1.5 binaries
wget https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_linux_amd64.zip
apt update
apt install unzip
unzip terraform_1.1.5_linux_amd64.zip
mv terraform /usr/local/bin
terraform version
2. Configure terraform provider to connect to local k8s
file : provider.tf
---------------
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.11.0"
}
}
}
provider "kubernetes" {
config_path = "/root/.kube/config"
config_context = "kubernetes-admin@kubernetes"
}
file : deployment.tf
--------------
resource "kubernetes_deployment" "frontend" {
metadata {
name = "frontend"
labels = {
name = "frontend"
}
}
spec {
replicas = 4
selector {
match_labels = {
name = "webapp"
}
}
template {
metadata {
labels = {
name = "webapp"
}
}
spec {
container {
image = "kodekloud/webapp-color:v1"
name = "simple-webapp"
port { container_port = 8080}
}
}
}
}
}
file : service.tf
------------
resource "kubernetes_service" "webapp-service" {
metadata {
name = "webapp-service"
}
spec {
selector = {
name = frontend
}
port {
port = 8080
NodePort = 30080
}
*
type = "NodePort"
}
}
# Launch everything
terraform init && terraform plan && terraform apply -auto-approve