gateway-deployment.yaml
Download gateway-deployment.yaml as it is.
apiVersion: apps/v1kind: Deploymentmetadata: name: houradvantage-gateway labels: app.kubernetes.io/name: houradvantage app.kubernetes.io/component: gatewayspec: # No replicas: the HorizontalPodAutoscaler owns the count (2..10), and a # fixed number here would reset it on every apply. revisionHistoryLimit: 5 selector: matchLabels: app.kubernetes.io/name: houradvantage app.kubernetes.io/component: gateway strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 template: metadata: labels: app.kubernetes.io/name: houradvantage app.kubernetes.io/component: gateway # /metrics on the admin port needs the admin login or an install # token (the probes are the routes with none), so scraping is set up in # the Prometheus: a scrape job or a PodMonitor on port 9090 that sends # the token (`authorization` with a credentials file, or the monitor's # bearer token secret). Pod annotations alone would be refused (401). spec: automountServiceAccountToken: false # Covers the preStop sleep (20 s) and then the gateway's own stop: its # drain (6 s), closing listeners and deliveries (up to 5 s), the # attendance workers ending a batch (up to 15 s, from the start of the # drain) and the admin API (up to 5 s), about 20 s in all, with room. terminationGracePeriodSeconds: 60 securityContext: runAsNonRoot: true runAsUser: 10001 runAsGroup: 10001 seccompProfile: type: RuntimeDefault topologySpreadConstraints: # One pod per node before any node gets a second. - maxSkew: 1 topologyKey: kubernetes.io/hostname whenUnsatisfiable: DoNotSchedule # Tainted nodes (dedicated ones, for example) do not count as places the # pods could have gone. nodeTaintsPolicy: Honor labelSelector: matchLabels: app.kubernetes.io/name: houradvantage app.kubernetes.io/component: gateway - maxSkew: 1 topologyKey: topology.kubernetes.io/zone whenUnsatisfiable: ScheduleAnyway labelSelector: matchLabels: app.kubernetes.io/name: houradvantage app.kubernetes.io/component: gateway containers: - name: gateway image: houradvantage imagePullPolicy: IfNotPresent # The image runs `hourd run`. Packages are kept in # Postgres (setup-job.yaml pushes the bundles the image carries), # so a pod starts with no package files. The image also sets the admin API on 0.0.0.0:9090 (the probes, # Prometheus and the setup Job reach it on the pod network; off # loopback it insists on the login below). The # gateway logs JSON lines to stdout (it is not a terminal) and # drains for 6 s on SIGTERM. env: # Secrets are read from files (the Secret mounted below), which # keeps them out of the environment, `kubectl describe` and # /proc/<pid>/environ. - name: HOURADVANTAGE_DATABASE_URL_FILE value: /run/secrets/houradvantage/database-url # The Valkey the pods share (valkey-statefulset.yaml): their cache and their messages to each other. With it any # number of pods share the database; without it a pod is the only one and refuses to start beside another. For a # Valkey of your own (Sentinel, a managed service) its URL here (redis-sentinel://, rediss://), and the install's id, # the first part of every key, which keeps installs apart in one Valkey. - name: HOURADVANTAGE_CACHE_URL value: redis://houradvantage-valkey:6379 - name: HOURADVANTAGE_CACHE_INSTALL value: default # Behind PgBouncer in transaction mode: the database itself, for # the connections that keep a session (and the key in `items`). # - name: HOURADVANTAGE_DATABASE_SESSION_URL_FILE # value: /run/secrets/houradvantage/database-session-url - name: HOURADVANTAGE_ADMIN_PASSWORD_HASH_FILE value: /run/secrets/houradvantage/admin-password-hash - name: HOURADVANTAGE_SECRET_KEY_FILE value: /run/secrets/houradvantage/secret-key # Also the user `kubectl exec ... hourctl` logs in as; the # password is given per command (HOURADVANTAGE_ADMIN_PASSWORD). - name: HOURADVANTAGE_ADMIN_USERNAME valueFrom: secretKeyRef: { name: houradvantage-gateway, key: admin-username } # Time and Attendance beside Connect on every pod: "on" or "off". # On, create its tenants with `hourctl attend tenants create`; # the pods' egress and the database need nothing more. - name: HOURADVANTAGE_ATTEND value: "off" # The pod name: distinct per pod and kept across container # restarts. MQTT client ids are built from it. A Deployment's pod # names change when a pod is replaced; if persistent MQTT sessions # must survive rescheduling, run this as a StatefulSet # (houradvantage-gateway-0, -1, ...) instead. - name: HOURADVANTAGE_INSTANCE_ID valueFrom: fieldRef: { fieldPath: metadata.name } # Where the other pods reach this one's admin API (9090) for the # live views across every pod (`hourctl wire`, `hourctl # stream`): pods reach each other directly on the pod network. # networkpolicy.yaml lets gateway pods reach each other on 9090. # They prove themselves to each other with a token derived from # HOURADVANTAGE_SECRET_KEY. - name: POD_IP valueFrom: fieldRef: { fieldPath: status.podIP } # The database pool, worker threads and Lua concurrency follow the # CPU limit (pool: 4 per CPU, 8..32, so 8 here). Without a CPU # limit the pod would size itself for the whole node: then set # HOURADVANTAGE_CPUS. # - name: HOURADVANTAGE_CPUS # value: "2" ports: # Admin API, health and /metrics. The device ports are listeners # (runtime config, in Postgres), exposed by devices-service.yaml # only: declaring a container port is informational, so they are # listed in one place. - name: admin containerPort: 9090 # Worker threads, Lua concurrency and the database pool all follow # the CPU limit. Requests equal to limits: Guaranteed QoS, and the # HPA's percentage is of the full 2 CPUs. resources: requests: cpu: "2" memory: 1Gi limits: cpu: "2" memory: 1Gi # 503 while starting and while draining: takes the pod out of the # Services' endpoints. Not tied to Postgres: a slow database would # take every pod out at once. readinessProbe: httpGet: path: /api/ready port: admin periodSeconds: 2 timeoutSeconds: 2 failureThreshold: 2 # 200 whenever the process answers, from the moment the admin # listener opens (before migrations), so no startupProbe is needed; # it asks nothing of the database: an outage must not restart # every pod. livenessProbe: httpGet: path: /livez port: admin periodSeconds: 10 timeoutSeconds: 3 failureThreshold: 3 # A pod being deleted leaves the Services' endpoints at once, but # kube-proxy on every node and the cloud balancer (which checks # nodes every few seconds, with externalTrafficPolicy Local) take # a while to stop sending to it. The sleep keeps it serving # meanwhile; SIGTERM, and the gateway's own 6 s drain, come after. # The sleep action needs Kubernetes 1.30 or newer; on older ones # use exec: { command: ["sleep", "20"] } (the image has sleep). lifecycle: preStop: sleep: seconds: 20 securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true capabilities: drop: ["ALL"] # The gateway writes no files: its log goes to stdout. volumeMounts: - name: tmp mountPath: /tmp - name: secrets mountPath: /run/secrets/houradvantage readOnly: true volumes: - name: tmp emptyDir: sizeLimit: 64Mi - name: secrets secret: secretName: houradvantage-gateway defaultMode: 0440 items: - { key: database-url, path: database-url } # - { key: database-session-url, path: database-session-url } - { key: admin-password-hash, path: admin-password-hash } - { key: secret-key, path: secret-key }