# Exposes an in-cluster Service through a relay, without Helm. The client
# creates its identity on first start and keeps it on the volume, so the URL
# survives restarts. tunnel.values.yaml is the same deployment for the chart.
#
#   kubectl apply -f tunnel.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-app-tunnel
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests:
      storage: 64Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-tunnel
spec:
  replicas: 1
  # One ReadWriteOnce volume holds the identity.
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/name: my-app-tunnel
  template:
    metadata:
      labels:
        app.kubernetes.io/name: my-app-tunnel
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
        runAsGroup: 65532
        fsGroup: 65532
        fsGroupChangePolicy: OnRootMismatch
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: tunnel
          image: ghcr.io/gosuda/portal-tunnel:2
          args:
            - expose
            - --name
            - my-app
            - --relays
            - https://portal.example.com
            - --discovery=false
            - --metrics-addr
            - ":9090"
            - my-app.default.svc.cluster.local:8080
          ports:
            - name: metrics
              containerPort: 9090
          livenessProbe:
            httpGet:
              path: /metrics
              port: metrics
            periodSeconds: 20
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: [ALL]
          volumeMounts:
            # The image keeps IDENTITY_PATH here.
            - name: identity
              mountPath: /identity
      volumes:
        - name: identity
          persistentVolumeClaim:
            claimName: my-app-tunnel
