# Kubernetes Deployment Example # Shows complete K8s deployment with services, volumes, and monitoring import provisioning.k8s_deploy as k8s_mod # Web application deployment in Kubernetes webapp_k8s: k8s_mod.K8sDeploy = k8s_mod.K8sDeploy { name: "webapp" namespace: "production" create_ns: True # Deployment specification spec: k8s_mod.K8sDeploySpec { replicas: 3 containers: [ k8s_mod.K8sContainers { name: "webapp" image: "nginx:1.21-alpine" # Port configuration ports: [ k8s_mod.K8sPort { name: "http" container: 80 target: 8080 } ] # Resource requirements resources_requests: k8s_mod.K8sResources { memory: "64Mi" cpu: "50m" } resources_limits: k8s_mod.K8sResources { memory: "128Mi" cpu: "100m" } # Environment variables env: [ k8s_mod.K8sKeyVal { key: "NODE_ENV" value: "production" }, k8s_mod.K8sKeyVal { key: "LOG_LEVEL" value: "info" } ] # Mount configuration volume volumeMounts: [ k8s_mod.K8sVolumeMount { name: "config" mountPath: "/etc/nginx/conf.d" readOnly: True } ] } ] # Volume configuration volumes: [ k8s_mod.K8sVolume { name: "config" typ: "configMap" configMap: k8s_mod.K8sConfigMap { name: "webapp-config" } } ] # Node selection for production workloads nodeSelector: [ k8s_mod.K8sKeyVal { key: "node-type" value: "production" } ] # Anti-affinity to spread pods across nodes affinity: k8s_mod.K8sAffinity { antiAffinity: k8s_mod.K8sAntyAffinityLabelSelector { typ: "preferredDuringSchedulingIgnoredDuringExecution" weight: 100 labelSelector: [ k8s_mod.K8sAffinityMatch { key: "app" operator: "In" values: ["webapp"] } ] topologyKey: "kubernetes.io/hostname" } } } # Service configuration service: k8s_mod.K8sService { name: "webapp-service" typ: "ClusterIP" ports: [ k8s_mod.K8sPort { name: "http" target: 80 nodePort: 30080 } ] selector: [ k8s_mod.K8sKeyVal { key: "app" value: "webapp" } ] } # Labels for the deployment labels: [ k8s_mod.K8sKeyVal { key: "app" value: "webapp" }, k8s_mod.K8sKeyVal { key: "version" value: "v1.0.0" }, k8s_mod.K8sKeyVal { key: "environment" value: "production" } ] } # Database deployment with persistent storage database_k8s: k8s_mod.K8sDeploy = k8s_mod.K8sDeploy { name: "postgres" namespace: "production" spec: k8s_mod.K8sDeploySpec { replicas: 1 # Database typically runs single instance containers: [ k8s_mod.K8sContainers { name: "postgres" image: "postgres:15-alpine" ports: [ k8s_mod.K8sPort { name: "postgres" container: 5432 target: 5432 } ] # Database needs more resources resources_requests: k8s_mod.K8sResources { memory: "256Mi" cpu: "100m" } resources_limits: k8s_mod.K8sResources { memory: "512Mi" cpu: "500m" } # Database environment env: [ k8s_mod.K8sKeyVal { key: "POSTGRES_DB" value: "webapp" }, k8s_mod.K8sKeyVal { key: "POSTGRES_USER" value: "webapp" }, k8s_mod.K8sKeyVal { key: "POSTGRES_PASSWORD" value: "changeme" # Use secrets in production } ] # Persistent data volume volumeMounts: [ k8s_mod.K8sVolumeMount { name: "postgres-data" mountPath: "/var/lib/postgresql/data" readOnly: False } ] } ] # Persistent volume for database volumes: [ k8s_mod.K8sVolume { name: "postgres-data" typ: "volumeClaim" persistentVolumeClaim: k8s_mod.K8sVolumeClaim { name: "postgres-pvc" storageClassName: "manual" storage: "10Gi" modes: ["ReadWriteOnce"] reclaimPolicy: "Retain" } } ] } # Internal service for database service: k8s_mod.K8sService { name: "postgres-service" typ: "ClusterIP" ports: [ k8s_mod.K8sPort { name: "postgres" target: 5432 } ] selector: [ k8s_mod.K8sKeyVal { key: "app" value: "postgres" } ] } labels: [ k8s_mod.K8sKeyVal { key: "app" value: "postgres" }, k8s_mod.K8sKeyVal { key: "component" value: "database" } ] } # Monitoring deployment using Prometheus monitoring_k8s: k8s_mod.K8sDeploy = k8s_mod.K8sDeploy { name: "prometheus" namespace: "monitoring" create_ns: True spec: k8s_mod.K8sDeploySpec { replicas: 1 containers: [ k8s_mod.K8sContainers { name: "prometheus" image: "prom/prometheus:v2.40.0" ports: [ k8s_mod.K8sPort { name: "web" container: 9090 target: 9090 } ] resources_requests: k8s_mod.K8sResources { memory: "512Mi" cpu: "200m" } resources_limits: k8s_mod.K8sResources { memory: "1Gi" cpu: "500m" } volumeMounts: [ k8s_mod.K8sVolumeMount { name: "prometheus-config" mountPath: "/etc/prometheus" readOnly: True }, k8s_mod.K8sVolumeMount { name: "prometheus-data" mountPath: "/prometheus" readOnly: False } ] } ] volumes: [ k8s_mod.K8sVolume { name: "prometheus-config" typ: "configMap" configMap: k8s_mod.K8sConfigMap { name: "prometheus-config" } }, k8s_mod.K8sVolume { name: "prometheus-data" typ: "volumeClaim" persistentVolumeClaim: k8s_mod.K8sVolumeClaim { name: "prometheus-pvc" storage: "20Gi" storageClassName: "manual" modes: ["ReadWriteOnce"] } } ] } service: k8s_mod.K8sService { name: "prometheus-service" typ: "NodePort" ports: [ k8s_mod.K8sPort { name: "web" target: 9090 nodePort: 30090 } ] } labels: [ k8s_mod.K8sKeyVal { key: "app" value: "prometheus" }, k8s_mod.K8sKeyVal { key: "component" value: "monitoring" } ] }