Add KCL deployment configuration and application setup for nginx
This commit is contained in:
parent
6d793e89b3
commit
c4a1f3aefd
8
air.toml
Normal file
8
air.toml
Normal file
@ -0,0 +1,8 @@
|
||||
# air.toml
|
||||
root = "." # 监听的项目目录
|
||||
|
||||
[build]
|
||||
cmd = "echo 'File changed, running KCL...' && kcl main.k" # 自定义命令
|
||||
bin = "" # 不生成二进制文件
|
||||
exclude_dir = ["vendor", "node_modules"] # 排除某些目录
|
||||
include_ext = ["k"] # 监听 `.k` 文件
|
@ -1,22 +1,44 @@
|
||||
import k8s.api.apps.v1 as appsv1
|
||||
import k8s.api.core.v1 as corev1
|
||||
|
||||
a = appsv1.Deployment {
|
||||
schema App:
|
||||
"""App schema"""
|
||||
name: str
|
||||
replicas: int = 1
|
||||
image: str
|
||||
port: int
|
||||
|
||||
appRender = lambda a: App {
|
||||
deployment = appsv1.Deployment {
|
||||
apiVersion = "apps/v1"
|
||||
kind = "Deployment"
|
||||
metadata = {
|
||||
name = "nginx"
|
||||
labels.app = "nginx"
|
||||
name = a.name
|
||||
labels.app = a.name
|
||||
}
|
||||
spec = {
|
||||
replicas = 3
|
||||
replicas = a.replicas
|
||||
selector.matchLabels = metadata.labels
|
||||
template.metadata.labels = metadata.labels
|
||||
template.spec.containers = [
|
||||
{
|
||||
name = metadata.name
|
||||
image = "nginx:1.14.2"
|
||||
ports = [{ containerPort = 80 }]
|
||||
name = a.name
|
||||
image = a.image
|
||||
ports = [{containerPort = a.port}]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
service = corev1.Service {
|
||||
apiVersion = "v1"
|
||||
kind = "Service"
|
||||
metadata = {
|
||||
name = a.name
|
||||
}
|
||||
spec = {
|
||||
selector.app = a.name
|
||||
ports = [{port = a.port, targetPort = a.port}]
|
||||
}
|
||||
}
|
||||
[deployment, service]
|
||||
}
|
||||
|
21
main.k
21
main.k
@ -1 +1,20 @@
|
||||
The_first_kcl_program = 'Hello World!'
|
||||
import base
|
||||
|
||||
import manifests
|
||||
|
||||
base.App {
|
||||
name = "myapp"
|
||||
replicas = 2
|
||||
image = "myimage"
|
||||
port = 8080
|
||||
}
|
||||
base.App {
|
||||
name = "myapp122"
|
||||
replicas = 2
|
||||
image = "myimage"
|
||||
port = 8080
|
||||
}
|
||||
|
||||
|
||||
# base.appRender(a)
|
||||
manifests.yaml_stream([base.appRender(a) for a in base.App.instances()])
|
||||
|
1
tmp/build-errors.log
Normal file
1
tmp/build-errors.log
Normal file
@ -0,0 +1 @@
|
||||
exit status 1exit status 2exit status 1exit status 1exit status 1exit status 1
|
Loading…
x
Reference in New Issue
Block a user