Bobcares

Kubectl Cloudflare Access | Behind-the-scenes

by | Jan 27, 2023

Are you wondering how to connect with Cloudflare Access via kubectl? Our Cloudflare Support team is here to lend a hand with your queries and issues.

How to connect via Cloudflare Access with kubectl

If you are looking for a guide to help you connect via Cloudflare Access with kubectl, you are in the right place. According to our experts, we can do this through Cloudflare’s Zero Trust platform as seen below:

  1. First, head to the Zero Trust dashboard and choose the Applications page from the sidebar.
  2. Then, select the Add an Application option.
  3. After that, select the Self-hosted option.
  4. Next, we have to enter a subdomain in the Application Domain. This is the hostname where our application will be accessible to users.
  5. Now we have to create rules in order to have control over who has access to the application.
  6. Finally, click Save.

 Kubectl Cloudflare Access | Behind-the-scenes

After that above process, we have to install cloudflared. This is a lightweight daemon that creates a Cloudflare tunnel. Once we install it, the next step is to authenticate it with the following code:

$ cloudflared tunnel login

Once, we create a tunnel with the following command, we have to configure it as well.

$ cloudflared tunnel create

We can easily configure the tunnel by creating a YAML file in the same folder where we installed cloudflared. Then, we have to add the following content (remember to replace the ID with the ID of the tunnel we created earlier):

tunnel: 7gg42ae3-876d-4acf-8223-421e66c1885efcredentials-file: /root/.cloudflared/7gg42ae3-876d-4acf-8223-421e66c1885ef.json
ingress: - hostname: azure.widgetcorp.tech service: tcp://kubernetes.docker.internal:6443 originRequest: proxyType: socks - service: http_status:404 # Catch-all rule, which responds with 404 if traffic doesn't match any of # the earlier rules

How to route to the Cloudflare Tunnel

In order to route traffic to the tunnel we created above, we have to create a DNS record.

  1. First, we have to log into the Cloudflare dashboard.
  2. Then, we have to open the external link and select our account.
  3. After that, choose our domain and head to DNS.
  4. Next, we must choose Add record and add CNAME as the record type.

    Remember to choose the hostname where we want to create the tunnel as the Name. This has to match the hostname of the Access policy.

    Then, enter the Tunnel id followed by .cfargotunnel.com as the Target.

  5. Finally, click Save.

Now, we can run the tunnel in order to connect to the target service with the following command:

$ cloudflared tunnel run

Furthermore, we can connect from a client machine easily.

Once this service is up and running, we can run the kubectl command. This pushes cloudflared to launch a browser window and then prompts the user to authenticate the SSO provider. After authentication, cloudflared exposes the connection to the client machine at the local URL mentioned in the command.

Let us know in the comments if you need further help connecting via Cloudflare Access with kubectl.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

To sum up, our Support Engineers demonstrated how to connect via Cloudflare Access with kubectl.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.