Tutorial Tutorial Cloudflare One Cloudflare One ~10 phút ~10 min Đồng bộ 2026-06-10 Synced 2026-06-10

Kết nối through Cloudflare Access using kubectl Connect through Cloudflare Access using kubectl

Hướng dẫn chi tiết đồng bộ từ docs Cloudflare — mỗi section có backlink tới đúng vị trí trên trang gốc. Detailed guide synced from Cloudflare docs — each section links to the matching anchor on the official page.

← Danh mục ← Catalog

Giải thích nhanh Quick context

Thuộc Cloudflare One — Zero Trust, truy cập an toàn và kiểm soát traffic người dùng/thiết bị. Tutorial «Kết nối through Cloudflare Access using kubectl» giúp bạn làm quen luồng triển khai thật — phù hợp đọc trước khi mở tài liệu gốc tiếng Anh. Đọc phần tóm tắt và lưu ý trước — sau đó mở docs gốc để copy lệnh và cấu hình chi tiết.

Connecting to Cloudflare's network using kubectl. Create a Zero Trust policy for your machine. Create an outbound-only connection between your machine and Cloudflared's network.

Lưu ý trước khi làm Notes before you start

  • Đây là bản tóm tắt trên Orange Cloud Learning Hub — không thay thế tài liệu chính thức. This is a summary on Orange Cloud Learning Hub — it does not replace the official documentation.
  • Luôn mở liên kết «Tài liệu gốc» bên dưới khi cần lệnh CLI, snippet code và ảnh minh họa đầy đủ. Open the Official docs link below for CLI commands, code snippets, and full screenshots.
  • Zero Trust thường cần quyền admin trên tenant Cloudflare One và IdP đã kết nối. Zero Trust typically requires Cloudflare One tenant admin access and a connected IdP.
  • Docs Cloudflare cập nhật thường xuyên — đối chiếu ngày «Rà soát lần cuối» trên trang gốc khi triển khai production. Cloudflare docs change frequently — verify the Last reviewed date on the official page before production use.

Tài liệu gốc — rà soát lần cuối: almost 4 years ago Official docs — last reviewed: almost 4 years ago

Tổng quan Overview

Phần «Tổng quan» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Overview" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

You can connect to machines over kubectl using Cloudflare's Zero Trust platform.

This walkthrough covers how to:

  • Build a policy in Cloudflare Access to secure the machine
  • Connect a machine to Cloudflare's network using kubectl
  • Connect from a client machine

Before you start

Time to complete:

30 minutes

---

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Tạo Access policy Create an Access policy

Phần «Tạo Access policy» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Create an Access policy" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗
  1. In the Cloudflare dashboard ↗, go to Zero Trust \> Access controls \> Applications.
  2. Select Create new application.
  3. Select Self-hosted and private.
  4. Select Add public hostname and input a subdomain. This will be the hostname where your application will be available to users.
  5. Create a new policy to control who can reach the application, or select existing policies.
  6. Follow the remaining self-hosted application creation steps to publish the application.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Cài đặt cloudflared Install cloudflared

Phần «Cài đặt cloudflared» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Install cloudflared" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Cloudflare Tunnel creates a secure, outbound-only connection between this machine and Cloudflare's network. With an outbound-only model, you can prevent any direct access to this machine and lock down any externally exposed points of ingress. And with that, no open firewall ports.

Cloudflare Tunnel is made possible through a lightweight daemon from Cloudflare called cloudflared. Download and install cloudflared on the DigitalOcean machine by following the instructions listed on the Downloads page.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Authenticate cloudflared Authenticate cloudflared

Phần «Authenticate cloudflared» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Authenticate cloudflared" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Run the following command to authenticate cloudflared into your Cloudflare account.

Terminal window

text
cloudflared tunnel login

cloudflared will open a browser window and prompt you to log in to your Cloudflare account. If you are working on a machine that does not have a browser, or a browser window does not launch, you can copy the URL from the command-line output and visit the URL in a browser on any machine.

Choose any hostname presented in the list. Cloudflare will issue a certificate scoped to your account. You do not need to pick the specific hostname where you will serve the Tunnel.

Tạo Tunnel Create a Tunnel

Phần «Tạo Tunnel» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Create a Tunnel" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

Next, create a tunnel with the command below.

Terminal window

text
cloudflared tunnel create <NAME>

Replacing <NAME> with a name for the Tunnel. This name can be any value. A single Tunnel can also serve traffic for multiple hostnames to multiple services in your environment, including a mix of connection types like SSH and HTTP.

The command will output an ID for the Tunnel and generate an associated credentials file. At any time you can list the Tunnels in your account with the following command.

Terminal window

text
cloudflared tunnel list

Cấu hình Tunnel Configure the Tunnel

Phần «Cấu hình Tunnel» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Configure the Tunnel" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

You can now configure the tunnel to serve traffic.

Create a YAML file that cloudflared can reach. By default, cloudflared will look for the file in the same folder where cloudflared has been installed.

Terminal window

text
vim ~/.cloudflared/config.yml

Next, configure the Tunnel, replacing the example ID below with the ID of the Tunnel created above. Additionally, replace the hostname in this example with the hostname of the application configured with Cloudflare Access.

YAML

text
tunnel: 6ff42ae2-765d-4adf-8112-31c55c1551ef

credentials-file: /root/.cloudflared/6ff42ae2-765d-4adf-8112-31c55c1551ef.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

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Route to Tunnel Route to the Tunnel

Phần «Route to Tunnel» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Route to the Tunnel" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

You can now create a DNS record that will route traffic to this Tunnel. Multiple DNS records can point to a single Tunnel and will send traffic to the configured service as long as the hostname is defined with an ingress rule.

  1. Log in to the Cloudflare dashboard ↗ and go to the DNS Records page for your domain.

Go to Records

  1. Select Add record. Choose CNAME as the record type. For Name, choose the hostname where you want to create a Tunnel. This should match the hostname of the Access policy.
  2. For Target, input the ID of your Tunnel followed by .cfargotunnel.com. For example:
text
6ff42ae2-765d-4adf-8112-31c55c1551ef.cfargotunnel.com
  1. Select Save.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Chạy Tunnel Run the Tunnel

Phần «Chạy Tunnel» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Run the Tunnel" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

You can now run the Tunnel to connect the target service to Cloudflare. Use the following command to run the Tunnel, replacing <NAME> with the name created for your Tunnel.

Terminal window

text
cloudflared tunnel run <NAME>

We recommend that you run cloudflared as a service that is configured to launch on start.

Liên kết liên quan (docs Cloudflare) Related links (Cloudflare docs)

Kết nối từ client machine Connect from a client machine

Phần «Kết nối từ client machine» — đọc hướng dẫn bên dưới, dùng liên kết docs gốc để xem ảnh minh họa và tab cấu hình đầy đủ.

Read the "Connect from a client machine" section below — open the official docs link for full screenshots and configuration tabs.

Mở section docs gốc ↗ Open source section ↗

You can now connect from a client machine using cloudflared.

This example uses a macOS laptop. On macOS, you can install cloudflared with the following command using Homebrew.

Terminal window

text
brew install cloudflared

Run the following command to create a connection from the device to Cloudflare. Any available port can be specified.

Terminal window

text
cloudflared access tcp --hostname azure.widgetcorp.tech --url 127.0.0.1:1234

With this service running, you can run a kubectl command and cloudflared will launch a browser window and prompt the user to authenticate with your SSO provider. Once authenticated, cloudflared will expose the connection to the client machine at the local URL specified in the command.

kubeconfig does not support proxy command configurations at this time, though the community has submitted plans to do so. In the interim, users can alias the cluster's API server to save time.

Terminal window

text
alias kubeone="env HTTPS_PROXY=socks5://127.0.0.1:1234 kubectl"
json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/cloudflare-one/","name":"Cloudflare One"}},{"@type":"ListItem","position":3,"item":{"@id":"/cloudflare-one/tutorials/","name":"Tutorials"}},{"@type":"ListItem","position":4,"item":{"@id":"/cloudflare-one/tutorials/kubectl/","name":"Connect through Cloudflare Access using kubectl"}}]}

Xem bản đầy đủ trên developers.cloudflare.com (ảnh, tab cấu hình). View the full guide on developers.cloudflare.com (images, config tabs).

Tài liệu gốc ↗ Official docs ↗