apiVersion: apps/v1
kind: Deployment
metadata:
  name: repowire-relay
  namespace: repowire
  labels:
    app: repowire-relay
spec:
  replicas: 2
  selector:
    matchLabels:
      app: repowire-relay
  template:
    metadata:
      labels:
        app: repowire-relay
    spec:
      containers:
      - name: relay
        image: us-docker.pkg.dev/baldmaninc/gcr.io/repowire-relay:latest
        ports:
        - containerPort: 8000
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 8000
          initialDelaySeconds: 10
          periodSeconds: 30
        readinessProbe:
          httpGet:
            path: /health
            port: 8000
          initialDelaySeconds: 5
          periodSeconds: 10
      - name: cloudflared
        image: cloudflare/cloudflared:latest
        args:
        - tunnel
        - --no-autoupdate
        - run
        - --url
        - http://localhost:8000
        env:
        - name: TUNNEL_TOKEN
          valueFrom:
            secretKeyRef:
              name: cloudflare-tunnel
              key: token
        resources:
          requests:
            memory: "64Mi"
            cpu: "50m"
          limits:
            memory: "128Mi"
            cpu: "100m"
---
apiVersion: v1
kind: Service
metadata:
  name: repowire-relay
  namespace: repowire
spec:
  type: ClusterIP
  ports:
  - port: 8000
    targetPort: 8000
  selector:
    app: repowire-relay
---
apiVersion: v1
kind: Secret
metadata:
  name: cloudflare-tunnel
  namespace: repowire
type: Opaque
stringData:
  token: "YOUR_TUNNEL_TOKEN_HERE"
