Sergiusz Bazanski | cb5c321 | 2019-05-19 03:10:17 +0200 | [diff] [blame] | 1 | # Factorio on Kubernetes. |
| 2 | |
| 3 | local kube = import "../../../kube/kube.libsonnet"; |
| 4 | |
| 5 | { |
| 6 | local factorio = self, |
| 7 | local cfg = factorio.cfg, |
| 8 | |
| 9 | cfg:: { |
| 10 | namespace: error "namespace must be set", |
| 11 | appName: "factorio", |
| 12 | storageClassName: "waw-hdd-redundant-1", |
| 13 | prefix: "", # if set, should be 'foo-' |
| 14 | |
| 15 | rconPort: 2137, |
| 16 | rconPassword: "farts", |
| 17 | |
| 18 | tag: "latest", |
| 19 | image: "registry.k0.hswaw.net/app/factorio:" + cfg.tag, |
| 20 | resources: { |
| 21 | requests: { |
| 22 | cpu: "500m", |
| 23 | memory: "500Mi", |
| 24 | }, |
| 25 | limits: { |
| 26 | cpu: "1", |
| 27 | memory: "1Gi", |
| 28 | }, |
| 29 | }, |
| 30 | }, |
| 31 | |
| 32 | |
| 33 | makeName(suffix):: cfg.prefix + suffix, |
| 34 | |
| 35 | metadata:: { |
| 36 | namespace: cfg.namespace, |
| 37 | labels: { |
| 38 | "app.kubernetes.io/name": cfg.appName, |
| 39 | "app.kubernetes.io/managed-by": "kubecfg", |
| 40 | "app.kubernetes.io/component": "factorio", |
| 41 | }, |
| 42 | }, |
| 43 | |
| 44 | volumeClaim: kube.PersistentVolumeClaim(factorio.makeName("factorio")) { |
| 45 | metadata+: factorio.metadata, |
| 46 | spec+: { |
| 47 | storageClassName: cfg.storageClassName, |
| 48 | accessModes: [ "ReadWriteOnce" ], |
| 49 | resources: { |
| 50 | requests: { |
| 51 | storage: "5Gi", |
| 52 | }, |
| 53 | }, |
| 54 | }, |
| 55 | }, |
| 56 | deployment: kube.Deployment(factorio.makeName("factorio")) { |
| 57 | metadata+: factorio.metadata, |
| 58 | spec+: { |
| 59 | replicas: 1, |
| 60 | template+: { |
| 61 | spec+: { |
| 62 | volumes_: { |
| 63 | data: kube.PersistentVolumeClaimVolume(factorio.volumeClaim), |
| 64 | }, |
| 65 | containers_: { |
| 66 | factorio: kube.Container(factorio.makeName("factorio")) { |
| 67 | image: cfg.image, |
| 68 | args: [ |
| 69 | "/entrypoint.sh", |
| 70 | "--rcon-port", std.toString(cfg.rconPort), |
| 71 | "--rcon-password", cfg.rconPassword, |
| 72 | ], |
| 73 | ports_: { |
| 74 | client: { containerPort: 34197 }, |
| 75 | rcon: { containerPort: cfg.rconPort }, |
| 76 | }, |
| 77 | volumeMounts_: { |
| 78 | data: { mountPath: "/data" }, |
| 79 | }, |
| 80 | resources: cfg.resources, |
| 81 | }, |
| 82 | }, |
| 83 | }, |
| 84 | }, |
| 85 | }, |
| 86 | }, |
| 87 | svc: kube.Service(factorio.makeName("factorio")) { |
| 88 | metadata+: factorio.metadata, |
| 89 | target_pod:: factorio.deployment.spec.template, |
| 90 | spec+: { |
| 91 | ports: [ |
| 92 | { name: "client", port: 34197, targetPort: 34197, protocol: "UDP" }, |
| 93 | ], |
| 94 | type: "LoadBalancer", |
| 95 | }, |
| 96 | }, |
| 97 | } |