forked from eclipse-xpanse/xpanse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexibleEngine-K8S.yml
322 lines (293 loc) · 14.7 KB
/
flexibleEngine-K8S.yml
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# The version of the Xpanse description language
version: 1.0
# The category of the service.
category: container
# The Service provided by the ISV, the name will be shown on the console as a service.
name: K8S-cluster
# The version of the service, the end-user can select the version they want to deploy.
serviceVersion: 1.0.0
# For the users may have more than one service, the @namespace can be used to separate the clusters.
description: This is an enhanced K8S cluster services by ISV-A.
namespace: ISV-A
# Icon for the service.
icon: |
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAmCAYAAACoPemuAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEyUlEQVR4nO1XW2geVRA+52yrVr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9VJWO0aYvD0NjgH4ar0/blenZbVZfVingFbY5aqIWP9AYMeB7nB2TRrDPOoC8seosJ1Y7VqpGS92G4tvxBPRh0Tu8ILq2McJhaOTlbkUas4o2avxBRgFXWt2OXs8AvW+A35Pf5UjupvVJbAd3XdqaOP6cckowPNcgfV5gYI/9POtO5mnkVypzk1ZVFfF9qaPJDA38ojiiSskFBunnArs71Oq+o1WhYHShQf6twMhu2SoqzkRttS+lH1L2z+0tNMjfFNjbK+StWpG0SN1hN8i/1MxMiaKQLSRLbLeOi0+LCngrpQhpqsmIc/3BrGthcIHxozs08FPyU+pNvqYMRHfJfibjS5qh0MFW1p0GsTVC3LxQqV8iVvjBa0dWMt8AbXcU+8vqkKU01G6Qvqrzcp899+OVE6RbnmVCvAKyDvQuu3ROSYL4kpo6Abu1LhdqaAHYUMqPNV/uozXNMxWRod0CiPKED/BBD+gGNZ1iixynCCwgVNMunTtnaqAn7J4v352Tez5O154mn3pH5P8u/wCL4t6vwR2T7QAAAABJRU5ErkJggg==
# Reserved for CSP: HuaweiCloud,FlexibleEngine,OpenstackTestlab,PlusServer,RegioCloud and ...
cloudServiceProvider:
name: FlexibleEngine
regions:
- name: eu-west-0
area: Western Europe
billing:
# The supported mode of billing (`Fixed`, `Pay per Use`)
billingModes:
- Fixed
serviceHostingType: self
# The flavor of the service, the @category/@name/@version/@flavor can locate the specific service to be deployed.
flavors:
serviceFlavors:
- name: 1-master-with-3-worker-nodes-normal
priority: 2
# The pricing of the flavor.
pricing:
# Used to calculate charges when users do not select 'pay_per_use' as the billing mode.
fixedPrice:
cost: 95.20
currency: EUR
period: monthly
# Properties for the service, which can be used by the deployment.
properties:
worker_nodes_count: 3
flavor_id: s6.large.2
features:
- High Availability
- Maximum performance
- name: 1-master-with-3-worker-nodes-performance
priority: 1
# The pricing of the flavor.
pricing:
# Used to calculate charges when users do not select 'pay_per_use' as the billing mode.
fixedPrice:
cost: 126.48
currency: EUR
period: monthly
# Properties for the service, which can be used by the deployment.
properties:
worker_nodes_count: 3
flavor_id: s6.large.4
features:
- High Availability
- Maximum performance
modificationImpact:
isDataLost: true
isServiceInterrupted: true
isDowngradeAllowed: true
# The contact details of the service.
serviceProviderContactDetails:
emails: [ "[email protected]" ]
deployment:
# kind, Supported values are terraform, opentofu.
kind: terraform
serviceAvailabilityConfigs:
- displayName: Availability Zone
varName: availability_zone
mandatory: false
description: The availability zone to deploy the service instance. If the value is empty, the service instance will be deployed in a random availability zone.
# Context for deployment: the context including some kind of parameters for the deployment, such as fix_env, fix_variable, env, variable, env_env, env_variable.
# - fix_env: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as environment variables. This variable is not visible to the end user.
# - fix_variable: Values for variable of this type are defined by the managed service provider in the OCL template. Runtime will inject it to deployer as usual variables. This variable is not visible to the end user.
# - env: Value for a variable of this type can be provided by end user. If marked as mandatory then end user must provide value to this variable. If marked as optional and if end user does not provided it, then the fallback value to this variable is read by runtime (it can read from other sources, e.g., OS env variables). This variable is injected as a environment variable to the deployer.
# - variable: Value for a variable of this type can be provided by end user. . If marked as mandatory then end user must provide value to this variable. If marked as optional and if end user does not provided it, then the fallback value to this variable is read by runtime (it can read from other sources, e.g., OS env variables). This variable is injected as a regular variable to the deployer.
# - env_env: Value to this variable is read by runtime (it can read from other sources, e.g., OS env variables) and injected as a environment variable to the deployer. End user cannot see or change this variable.
# - env_variable: Value to this variable is read by runtime (it can read from other sources, e.g., OS env variables) and injected as a regular variable to the deployer. End user cannot see or change this variable.
# The parameters will be used to generate the API of the managed service.
variables:
- name: admin_passwd
description: The admin password of all nodes in the K8S cluster instance. If the value is empty, will create a random password.
kind: variable
dataType: string
mandatory: false
valueSchema:
minLength: 8
maxLength: 16
pattern: ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,16}$
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: vpc_name
description: The vpc name of all nodes in the K8S cluster instance. If the value is empty, will use the example value to find or create VPC.
kind: variable
dataType: string
example: "k8s-vpc-default"
mandatory: false
value: "k8s-vpc-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: subnet_name
description: The sub network name of all nodes in the K8S cluster instance. If the value is empty, will use the default value to find or create subnet.
kind: variable
dataType: string
example: "k8s-subnet-default"
mandatory: false
value: "k8s-subnet-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
- name: secgroup_name
description: The security group name of all nodes in the K8S cluster instance. If the value is empty, will use the default value to find or create security group.
kind: variable
dataType: string
example: "k8s-secgroup-default"
mandatory: false
value: "k8s-secgroup-default"
modificationImpact:
isDataLost: true
isServiceInterrupted: true
deployer: |
variable "region" {
type = string
description = "The region to deploy the K8S cluster instance."
}
variable "availability_zone" {
type = string
default = ""
description = "The availability zone to deploy the K8S cluster instance."
}
variable "flavor_id" {
type = string
default = "s6.large.2"
description = "The flavor_id of all nodes in the K8S cluster instance."
}
variable "image_name" {
type = string
default = "OBS Ubuntu 22.04"
description = "The image name of the compute instance."
}
variable "worker_nodes_count" {
type = string
default = 3
description = "The worker nodes count in the K8S cluster instance."
}
variable "admin_passwd" {
type = string
default = ""
description = "The root password of all nodes in the K8S cluster instance."
}
variable "vpc_name" {
type = string
default = "k8s-vpc-default"
description = "The vpc name of all nodes in the K8S cluster instance."
}
variable "subnet_name" {
type = string
default = "k8s-subnet-default"
description = "The subnet name of all nodes in the K8S cluster instance."
}
variable "secgroup_name" {
type = string
default = "k8s-secgroup-default"
description = "The security group name of all nodes in the K8S cluster instance."
}
terraform {
required_providers {
flexibleengine = {
source = "FlexibleEngineCloud/flexibleengine"
version = "~> 1.45.0"
}
}
}
provider "flexibleengine" {
region = var.region
}
data "flexibleengine_availability_zones" "osc-az" {}
data "flexibleengine_vpc_v1" "existing" {
name = var.vpc_name
count = length(data.flexibleengine_vpc_v1.existing)
}
data "flexibleengine_vpc_subnet_v1" "existing" {
name = var.subnet_name
count = length(data.flexibleengine_vpc_subnet_v1.existing)
}
data "flexibleengine_networking_secgroup_v2" "existing" {
name = var.secgroup_name
count = length(data.flexibleengine_networking_secgroup_v2.existing)
}
locals {
availability_zone = var.availability_zone == "" ? data.flexibleengine_availability_zones.osc-az.names[0] : var.availability_zone
admin_passwd = var.admin_passwd == "" ? random_password.password.result : var.admin_passwd
vpc_id = length(data.flexibleengine_vpc_v1.existing) > 0 ? data.flexibleengine_vpc_v1.existing[0].id : flexibleengine_vpc_v1.new[0].id
subnet_id = length(data.flexibleengine_vpc_subnet_v1.existing) > 0 ? data.flexibleengine_vpc_subnet_v1.existing[0].id : flexibleengine_vpc_subnet_v1.new[0].id
secgroup_id = length(data.flexibleengine_networking_secgroup_v2.existing) > 0 ? data.flexibleengine_networking_secgroup_v2.existing[0].id : flexibleengine_networking_secgroup_v2.new[0].id
secgroup_name = length(data.flexibleengine_networking_secgroup_v2.existing) > 0 ? data.flexibleengine_networking_secgroup_v2.existing[0].name : flexibleengine_networking_secgroup_v2.new[0].name
}
resource "flexibleengine_vpc_v1" "new" {
count = length(data.flexibleengine_vpc_v1.existing) == 0 ? 1 : 0
name = "${var.vpc_name}-${random_id.new.hex}"
cidr = "192.168.0.0/16"
}
resource "flexibleengine_vpc_subnet_v1" "new" {
count = length(data.flexibleengine_vpc_subnet_v1.existing) == 0 ? 1 : 0
vpc_id = local.vpc_id
name = "${var.subnet_name}-${random_id.new.hex}"
cidr = "192.168.10.0/24"
gateway_ip = "192.168.10.1"
dns_list = ["100.125.0.41","100.125.12.161"]
}
resource "flexibleengine_networking_secgroup_v2" "new" {
count = length(data.flexibleengine_networking_secgroup_v2.existing) == 0 ? 1 : 0
name = "${var.secgroup_name}-${random_id.new.hex}"
description = "K8S cluster security group"
}
resource "flexibleengine_networking_secgroup_rule_v2" "secgroup_rule_0" {
count = length(data.flexibleengine_networking_secgroup_v2.existing) == 0 ? 1 : 0
direction = "ingress"
ethertype = "IPv4"
protocol = "tcp"
port_range_min = 22
port_range_max = 22
remote_ip_prefix = "121.37.117.211/32"
security_group_id = local.secgroup_id
}
resource "random_id" "new" {
byte_length = 4
}
resource "random_password" "password" {
length = 12
upper = true
lower = true
numeric = true
special = true
min_special = 1
override_special = "#%@"
}
resource "flexibleengine_compute_keypair_v2" "keypair" {
name = "keypair-k8s-${random_id.new.hex}"
}
data "flexibleengine_images_image" "image" {
name = var.image_name
most_recent = true
enterprise_project_id = "0"
}
resource "flexibleengine_compute_instance_v2" "k8s-master" {
availability_zone = local.availability_zone
name = "k8s-master-${random_id.new.hex}"
flavor_id = var.flavor_id
security_groups = [ local.secgroup_name ]
image_id = data.flexibleengine_images_image.image.id
key_pair = flexibleengine_compute_keypair_v2.keypair.name
network {
uuid = local.subnet_id
}
user_data = <<EOF
#!bin/bash
echo root:${local.admin_passwd} | sudo chpasswd
sudo sh /root/k8s-init.sh true ${local.admin_passwd} ${var.worker_nodes_count} > /root/init.log
EOF
}
resource "flexibleengine_compute_instance_v2" "k8s-node" {
count = var.worker_nodes_count
availability_zone = local.availability_zone
name = "k8s-node-${random_id.new.hex}-${count.index}"
flavor_id = var.flavor_id
security_groups = [ local.secgroup_name ]
image_id = data.flexibleengine_images_image.image.id
key_pair = flexibleengine_compute_keypair_v2.keypair.name
network {
uuid = local.subnet_id
}
user_data = <<EOF
#!bin/bash
echo root:${local.admin_passwd} | sudo chpasswd
sudo sh /root/k8s-init.sh false ${local.admin_passwd} ${var.worker_nodes_count} ${flexibleengine_compute_instance_v2.k8s-master.access_ip_v4} > /root/init.log
EOF
depends_on = [
flexibleengine_compute_instance_v2.k8s-master
]
}
output "k8s_master_host" {
value = flexibleengine_compute_instance_v2.k8s-master.access_ip_v4
}
output "admin_passwd" {
value = var.admin_passwd == "" ? nonsensitive(local.admin_passwd) : local.admin_passwd
}