Now that you have your Cluster up and running, and we are now running MySQL too, what if I want people to access it? you know like hosting my website on my PI then provide them with the URL? do I need a static IP and to configure my home router to do some port forwarding?

The simple answer is: No,  you can do that without any problem using Cloudflare Tunnel and you can do that for Free !! The only thing that I know you need is to:

  1. Own a domain name like "MyCoooooooldomain.com" or anything else.
  2. Manage your domain via Cloudflare DNS.

I am not going to talk about the features of Cloudflare tunnel, you can read about it from their site, plus by the time you read this article, their features might have changed.

To get your Cloudflare tunnel up and running, you will need to access your Zero Trust portal, which is also part of your Cloudflare free subscription, and go to Access -> Tunnels where have access to all your Tunnels and you can create one from there.

Clicking on the Create Tunnel button will ask you to do 3 main things:

  1. Name the tunnel.
  2. Install the connector.
  3. Define a route in the tunnel.


https://d.pr/i/s7LhF1

In the second question, you will presented with your Token as you can see in the above gif, you can choose the system you want to install the connector on, but since we are going to use containers we should select Docker and copy the key they provide.

Keep this Token with you are the will not show it to you any more.

Run cloudflared on K3s

It is not that hard to be honest, as we already have everything we need, and you only need to define two things:

  1. A namespace.
  2. A deployment.

The code is simple as you can check below:

apiVersion: v1
kind: Namespace
metadata:
  name: cloudflare-server

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloudflare
  namespace: cloudflare-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cloudflare
  template:
    metadata:
      labels:
        app: cloudflare
        name: cloudflare
    spec:
  
      nodeSelector:
        kubernetes.io/hostname: master
        
      containers:
        - name: cloudflare
          image: cloudflare/cloudflared:latest
          imagePullPolicy: Always
          args:
            - "tunnel"
            - "--no-autoupdate"
            - "run"
            - "--token"
            - "<add_your_token_here>"</add_your_token_here>

Basically, you pull the latest docker image, you pass some arguments and remember to replace <add_your_token_here></add_your_token_here> with the token you get when you created your tunnel.

Now all you have to execute is kubectl apply -f cloudflare.yml (assuming you have named the file cloudflare.yml).

In later articles, I'll talk about installing other services that you will be exposed to the outside world via Cloudflare Tunnel.