Add KCL deployment configuration and application setup for nginx

This commit is contained in:
2025-03-14 11:05:33 +08:00
parent 6d793e89b3
commit c4a1f3aefd
4 changed files with 68 additions and 18 deletions
+39 -17
View File
@@ -1,22 +1,44 @@
import k8s.api.apps.v1 as appsv1
import k8s.api.core.v1 as corev1
a = appsv1.Deployment {
apiVersion = "apps/v1"
kind = "Deployment"
metadata = {
name = "nginx"
labels.app = "nginx"
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 = a.name
labels.app = a.name
}
spec = {
replicas = a.replicas
selector.matchLabels = metadata.labels
template.metadata.labels = metadata.labels
template.spec.containers = [
{
name = a.name
image = a.image
ports = [{containerPort = a.port}]
}
]
}
}
spec = {
replicas = 3
selector.matchLabels = metadata.labels
template.metadata.labels = metadata.labels
template.spec.containers = [
{
name = metadata.name
image = "nginx:1.14.2"
ports = [{ containerPort = 80 }]
}
]
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]
}