# Deploy to Cloudflare

The control plane runs serverless in your Cloudflare account, so you run no
machines for it. Its Cloudflare usage costs cents a month, as
[Control plane costs](/docs/cost/) shows. It gets a `workers.dev` address, so you don't
need a domain.

## What you need

- A Mac or Linux machine with `curl` and `kubectl`.
- A Cloudflare account that can deploy Workers, with a `workers.dev` subdomain.
- An Ubuntu 24.04 or Debian 13 host, amd64 or arm64, with `curl` and at least 512 MiB of memory, that you can log in to as `root` over SSH. The host becomes a node. [Manage nodes](/docs/manage-nodes/#what-you-need) lists what other hosts need.

The host must reach the control plane over HTTPS. It needs only two inbound ports: SSH from your machine and, when you have more than one host, UDP 51820 from the other hosts.

## Install the CLI

```bash
curl -fsSL https://get.runkite.io | sh
```

If the installer tells you to, add `~/.local/bin` to your `PATH`.

## Deploy the control plane

<Steps>

1. In the Cloudflare dashboard, under **My Profile → API Tokens**, create a
   custom token with **API Tokens: Edit** that expires in a day. `kite` uses it
   once to create the token that later deploys use, then deletes it.

2. Set up and deploy:

   ```bash
   kite deploy init
   ```

   For a first cluster, answer no to your own hostname, choose the admin token
   only for sign-in, answer no to the audit log, and press return for each
   setting that can't change after the first deploy. When it asks for a token,
   paste the token from step 1.

   `kite deploy init` then shows what it will create, and asks once before it
   changes anything. Answer `y`. It prints the cluster's address, the path of
   its kubeconfig, and what to do next:

   ```text
       api     https://kite-control.<your-subdomain>.workers.dev
       kubectl export KUBECONFIG=/Users/you/.kite/deployments/kite-control/kubeconfig-break-glass

     join a host:        kite node add --deployment kite-control root@<host>
     teammates sign in:  not set up, so only the admin token works. Set KITE_ACCESS_ALLOW or KITE_OIDC_ISSUER in /Users/you/.kite/deployments/kite-control/deploy.env and deploy again.
     back up:            /Users/you/.kite/deployments/kite-control/deploy.env holds the only copy of the key to the cluster's Secrets
   ```

   With sign-in set up, the second line is the `kite login` command to send
   to the people who use the cluster. Keep a copy of `deploy.env` somewhere
   safe: without it, nobody can read the cluster's Secrets.

3. Check that the API responds:

   ```bash
   export KUBECONFIG=~/.kite/deployments/kite-control/kubeconfig-break-glass
   kubectl get nodes
   ```

   ```text
   No resources found
   ```

   That kubeconfig contains the admin credential. To add the cluster to your
   default kubeconfig as well, run `kite deploy --update-kubeconfig`.

</Steps>

<Aside type="caution" title="Back up ~/.kite/deployments">
  `~/.kite/deployments/kite-control/deploy.env` contains the key that encrypts the cluster's
  Secrets. Without it, nobody can read those Secrets again. Keep a private copy of the directory.
</Aside>

## Join a host

<Steps>

1. Add the host. `--deployment kite-control` tells `kite` to use the cluster
   that you deployed, with its admin token. The command connects to the host
   over SSH and installs containerd, the CNI plugins, WireGuard and the node
   agent. It prints the node's name once the node is `Ready`.

   ```bash
   kite node add --deployment kite-control root@<host>
   ```

2. Check the node:

   ```bash
   kubectl get nodes
   ```

</Steps>

## Run a workload

```bash
kubectl create deployment web --image=nginx:1.27-alpine --replicas=2
kubectl expose deployment web --port=80
kubectl rollout status deployment/web
kubectl get pods -o wide
```

To reach nginx, [forward a port](/docs/quickstart/#open-nginx) or
[expose it through Cloudflare Tunnel](/docs/expose/).

## If something goes wrong

| What you see                                              | What to do                                                                                                                                                                                                 |
| --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `this account has no workers.dev subdomain`               | Choose a `workers.dev` subdomain in the dashboard, under Workers & Pages, then deploy again. Nothing was changed.                                                                                          |
| `the token in … may not …`                                | Delete the API token `kite-deploy-<name>` in the dashboard, remove `CLOUDFLARE_API_TOKEN` from `deploy.env`, and run `kite deploy credentials` with `CLOUDFLARE_PROVISION_TOKEN` set. Nothing was changed. |
| `a Worker called kite-control is already in this account` | Copy `~/.kite/deployments/kite-control` from the machine that deployed it, or deploy under another name with `--name`.                                                                                     |
| The node isn't `Ready`                                    | On the host, run `kite-agent status`, then `kite-agent logs`.                                                                                                                                              |
| A pod stays `ContainerCreating`                           | Read the Events in `kubectl describe pod <name>`, then `kite-agent logs`.                                                                                                                                  |
| Pods on different hosts can't reach each other            | Open UDP 51820 between the hosts, in the host firewall and the cloud's security group.                                                                                                                     |

## Next

- [Sign in to a cluster](/docs/sign-in/): let your team use their own identity.
- [Manage nodes](/docs/manage-nodes/): add, upgrade, and remove hosts.
- [Configure a deployment](/docs/configure/): use your own domain and turn on audit logs.
