etherai / selfhosted-gateway

Self-hosted Docker native tunneling to localhost. Expose local docker containers to the public Internet via a simple docker compose interface.
https://fractalnetworks.co
GNU Affero General Public License v3.0
1.32k stars 66 forks source link

someone interessted in adding k8s support? #22

Closed egandro closed 1 year ago

egandro commented 1 year ago

I would love to use this for my k3s homelab cluster.

Anyone interessted in adding k8s support?

Thx.

jdollar commented 1 year ago

Idk if this will help anyone when trying to set this up inside K3S, but in my homelab cluster I got it working with a deployment similar to this (for a jellyfin setup):

# Source: jellyfin/templates/gateway-client-configmap.yaml
apiVersion: v1
data:
  EXPOSE: jellyfin.default.svc.cluster.local:8096
  LINK_DOMAIN: jellyfin.mydomain.com
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: jellyfin
    app.kubernetes.io/version: unstable
    helm.sh/chart: jellyfin-0.1.0
  name: jellyfin-gw-client

---
# Source: jellyfin/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: jellyfin
  labels:
    helm.sh/chart: jellyfin-0.1.0
    app.kubernetes.io/name: jellyfin
    app.kubernetes.io/version: "unstable"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 8096
      targetPort: http
      protocol: TCP
      name: http
    - port: 8920
      targetPort: https
      protocol: TCP
      name: https
    - port: 1900
      targetPort: sad
      protocol: UDP
      name: sad
    - port: 7359
      targetPort: ad
      protocol: UDP
      name: ad
  selector:
    app.kubernetes.io/name: jellyfin

---
# Source: jellyfin/templates/gateway-client-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jellyfin-gw-client
  labels:
    helm.sh/chart: jellyfin-0.1.0
    app.kubernetes.io/name: jellyfin
    app.kubernetes.io/instance: release-name
    app.kubernetes.io/version: "unstable"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: jellyfin
  template:
    metadata:
      labels:
        app.kubernetes.io/name: jellyfin
    spec:
      serviceAccountName: jellyfin
      securityContext:
        {}
      containers:
        - name: jellyfin
          securityContext:
            capabilities:
              add:
              - NET_ADMIN
          image: "mydockerusername/gateway-client:latest"
          imagePullPolicy: Always
          env:
          - name: GATEWAY_CLIENT_WG_PRIVKEY
            valueFrom:
              secretKeyRef:
                key: wgprivatekey
                name: jellyfin-gw-secret
                optional: false
          - name: GATEWAY_LINK_WG_PUBKEY
            valueFrom:
              secretKeyRef:
                key: wgpublickey
                name: jellyfin-gw-secret
                optional: false
          - name: GATEWAY_ENDPOINT
            valueFrom:
              secretKeyRef:
                key: entrypoint
                name: jellyfin-gw-secret
                optional: false
          envFrom:
            - configMapRef:
                name: jellyfin-gw-client
          resources: {}

I ran through the "gateway" steps on my vps and afterwards I ran the "gateway client" instructions (the ones that generate the docker-compose block) on my local machine. The key thing here though is that I updated the Make file to build the images (make docker) with my docker user so I could push the images out to dockerhub and use them within my cluster.

Ran make docker after updating the tag names and then ran docker push myusername/gateway-client. Would love to know if the fractalnetworksco images are hosted somewhere already though. I didn't immediately find them doing a quick google.

After doing that I just setup some manifests like above and directed the gateway-client pod to have "EXPOSE" pointing to the svc I have configured for jellyfin. Going to the http port. Seems to work fine from initial testing.

thebalaa commented 1 year ago

thanks for sharing @jdollar, check out https://gitlab.com/fractalnetworks/fractal-mosaic if you're interested in something a little more experimental that k3s