-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-k8s-manifests.lua
More file actions
72 lines (67 loc) · 1.53 KB
/
generate-k8s-manifests.lua
File metadata and controls
72 lines (67 loc) · 1.53 KB
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
-- generate-k8s-manifests.lua
local function generateDeployment(name, image, port, replicas)
local yaml = [[
apiVersion: apps/v1
kind: Deployment
metadata:
name: %s
spec:
replicas: %d
selector:
matchLabels:
app: %s
template:
metadata:
labels:
app: %s
spec:
containers:
- name: %s
image: %s
ports:
- containerPort: %d
]]
return string.format(yaml, name, replicas, name, name, name, image, port)
end
local function generateService(name, port, targetPort)
local yaml = [[
apiVersion: v1
kind: Service
metadata:
name: %s
spec:
selector:
app: %s
ports:
- protocol: TCP
port: %d
targetPort: %d
]]
return string.format(yaml, name, name, port, targetPort)
end
-- Advanced: Generate a deployment and service for multiple environments
local environments = {
{
name = "production",
image = "myregistry.example.com/my-web-app:prod",
port = 80,
replicas = 3,
targetPort = 8080,
},
{
name = "staging",
image = "myregistry.example.com/my-web-app:stage",
port = 8081,
replicas = 2,
targetPort = 8080,
},
}
-- Generate and print YAML for each environment
for _, env in ipairs(environments) do
local deploymentYAML = generateDeployment(env.name, env.image, env.port, env.replicas)
local serviceYAML = generateService(env.name, env.port, env.targetPort)
print("###", env.name, "###")
print(deploymentYAML)
print(serviceYAML)
print()
end