-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaws-k3s.yaml
217 lines (216 loc) · 6.67 KB
/
aws-k3s.yaml
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
{{- $createVpcCIDR := "10.8.0.0/18" -}}
{{- $region := .variables.region -}}
{{- $azs := list "" -}}
{{- if .variables.azs -}}
{{- $azs = .variables.azs -}}
{{- else -}}
{{- $azs = list (printf "%sa" $region) (printf "%sb" $region) (printf "%sc" $region) -}}
{{- end -}}
{{- $azs_count := len $azs -}}
_p: &provider_aws
- aws:
region: {{ .variables.region }}
name: aws-k3s
kind: StackTemplate
cliVersion: ">=v0.8.0"
units:
-
name: aws_key_pair
type: tfmodule
source: github.com/terraform-aws-modules/terraform-aws-key-pair?ref=v0.6.0
providers: *provider_aws
inputs:
create_key_pair: true
public_key: {{ .variables.public_key }}
key_name: {{ .variables.public_key_name }}
{{- if .variables.domain }}
-
name: route53
type: tfmodule
providers: *provider_aws
source: github.com/shalb/cluster.dev-domain?ref=0.1.0
inputs:
region: {{ .variables.region }}
cluster_name: {{ .variables.cluster_name }}
cluster_domain: {{ .variables.domain }}
zone_delegation: {{ if eq .variables.domain "cluster.dev" }}true{{ else }}false{{ end }}
{{- end }}
{{- if not .variables.vpc_id }}
-
name: vpc
type: tfmodule
providers: *provider_aws
source: terraform-aws-modules/vpc/aws
version: "4.0.2"
inputs:
name: {{ .variables.cluster_name }}
cidr: {{ $createVpcCIDR }}
enable_nat_gateway: true
map_public_ip_on_launch: true
single_nat_gateway: true
one_nat_gateway_per_az: false
enable_dns_hostnames: true
enable_dns_support: true
create_egress_only_igw: true
enable_vpn_gateway: true
create_database_subnet_group: true
public_subnets:
{{- range $index, $_ := $azs }}
- {{ cidrSubnet $createVpcCIDR 4 $index }}
{{- end }}
private_subnets:
{{- range $index, $_ := $azs }}
- {{ cidrSubnet $createVpcCIDR 4 (add $index $azs_count ) }}
{{- end }}
database_subnets:
{{- range $index, $_ := $azs }}
- {{ cidrSubnet $createVpcCIDR 4 (add $index $azs_count $azs_count ) }}
{{- end }}
public_subnet_tags:
"kubernetes.io/cluster/{{ .variables.cluster_name }}": "owned"
"kubernetes.io/role/lb": 1
private_subnet_tags:
"kubernetes.io/cluster/{{ .variables.cluster_name }}": "owned"
"kubernetes.io/role/internal-lb": 1
azs: {{ insertYAML $azs }}
{{- end }}
-
name: k3s
type: tfmodule
source: github.com/shalb/terraform-aws-k3s?ref=v0.5.0
providers: *provider_aws
inputs:
cluster_name: {{ .variables.cluster_name }}
extra_args:
- "--disable traefik"
{{ if .variables.domain }}
domain: {{ remoteState "this.route53.domain" }}
{{ end }}
k3s_version: {{ .variables.k3s_version }}
{{- if .variables.vpc_id }}
public_subnets: {{ insertYAML .variables.public_subnets }}
{{- else }}
public_subnets: {{ remoteState "this.vpc.public_subnets" }}
{{- end }}
key_name: {{ remoteState "this.aws_key_pair.this_key_pair_key_name" }}
region: {{ .variables.region }}
s3_bucket: {{ .variables.bucket }}
master_node_count: {{ .variables.master_node_count }}
worker_node_groups: {{ insertYAML .variables.worker_node_groups }}
master_iam_policies:
- {{ remoteState "this.iam-policy-external-dns.arn" }}
enable_asg_rolling_auto_update: true
-
name: kubeconfig
type: tfmodule
providers: *provider_aws
force_apply: true
depends_on: this.k3s
source: github.com/shalb/terraform-modules//local-file?ref=0.0.1
inputs:
filename: /tmp/kubeconfig_{{ .variables.cluster_name }}
source_s3:
bucket: {{ .variables.bucket }}
key: {{ .variables.cluster_name }}/kubeconfig
file_permission: "0600"
{{- if .variables.domain }}
-
name: iam-policy-external-dns
type: tfmodule
source: "terraform-aws-modules/iam/aws//modules/iam-policy"
version: "5.30.0"
providers: *provider_aws
inputs:
name: AllowRoute53ZoneManagement-{{ .variables.cluster_name }}
policy: |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:ChangeResourceRecordSets",
"route53:GetChange"
],
"Resource": [
"arn:aws:route53:::hostedzone/{{ .variables.domain }}",
"arn:aws:route53:::change/*"
]
},
{
"Effect": "Allow",
"Action": [
"route53:ListHostedZones",
"route53:ListResourceRecordSets",
"route53:ListHostedZonesByName"
],
"Resource": [
"*"
]
}
]
}
-
name: external-dns
type: helm
source:
repository: "https://charts.bitnami.com/bitnami"
chart: "external-dns"
version: "6.26.3"
kubeconfig: {{ remoteState "this.kubeconfig.path" }}
additional_options:
namespace: "external-dns"
create_namespace: true
values:
- file: ./values/external-dns.yaml
-
name: cert-manager
type: helm
source:
repository: "https://charts.jetstack.io"
chart: "cert-manager"
version: "v1.6.1"
kubeconfig: {{ output "this.kubeconfig.path" }}
additional_options:
namespace: "cert-manager"
create_namespace: true
inputs:
installCRDs: true
webhook.enabled: false
ingressShim.defaultIssuerName: letsencrypt-prod
ingressShim.defaultIssuerKind: ClusterIssuer
ingressShim.defaultACMEChallengeType: dns01
securityContext.enabled: false
serviceAccount.create: true
-
name: cert-manager-issuer
type: kubernetes
depends_on: this.cert-manager
source: ./cert-manager/issuer.yaml
kubeconfig: {{ remoteState "this.kubeconfig.path" }}
{{- end }}
-
name: ingress-nginx
type: helm
source:
repository: "https://kubernetes.github.io/ingress-nginx"
chart: "ingress-nginx"
version: "4.7.3"
kubeconfig: {{ output "this.kubeconfig.path" }}
additional_options:
namespace: "ingress-nginx"
create_namespace: true
timeout: 60
inputs:
service.type: LoadBalancer
controller.admissionWebhooks.enabled: false
service.externalTrafficPolicy: Local
controller.ingressClassResource.default: true
-
name: outputs
type: printer
outputs:
cluster_name: {{ .variables.cluster_name }}
region: {{ .variables.region }}
kubeconfig: {{ output "this.kubeconfig.path" }}
k3s_version: {{ .variables.k3s_version }}