show me how to deploy a k3s cluster in hetzner cloud
TypeScriptTo deploy a K3s cluster in Hetzner Cloud using Pulumi, you can use the
hcloud
provider. Below is a TypeScript program that sets up a K3s cluster on Hetzner Cloud.First, make sure you have the Pulumi CLI installed and configured, and the
@pulumi/hcloud
package installed.import * as pulumi from "@pulumi/pulumi"; import * as hcloud from "@pulumi/hcloud"; // Create a new SSH key const sshKey = new hcloud.SshKey("my-ssh-key", { publicKey: "<your-public-ssh-key-here>", }); // Create a new Hetzner Cloud network const network = new hcloud.Network("my-network", { ipRange: "10.0.0.0/16", }); // Create a subnet within the network const subnet = new hcloud.Subnet("my-subnet", { networkId: network.id, type: "cloud", networkZone: "eu-central", ipRange: "10.0.1.0/24", }); // Create a firewall to allow traffic to the K3s cluster const firewall = new hcloud.Firewall("my-firewall", { rules: [ { direction: "in", protocol: "tcp", port: "6443", sourceIps: ["0.0.0.0/0"], }, { direction: "in", protocol: "tcp", port: "80", sourceIps: ["0.0.0.0/0"], }, { direction: "in", protocol: "tcp", port: "443", sourceIps: ["0.0.0.0/0"], }, ], }); // Create a server for the K3s master node const master = new hcloud.Server("k3s-master", { serverType: "cx21", image: "ubuntu-20.04", sshKeys: [sshKey.name], networks: [network.id], firewallIds: [firewall.id], userData: `#!/bin/bash curl -sfL https://get.k3s.io | sh -`, }); // Create two servers for the K3s worker nodes const worker1 = new hcloud.Server("k3s-worker-1", { serverType: "cx21", image: "ubuntu-20.04", sshKeys: [sshKey.name], networks: [network.id], firewallIds: [firewall.id], userData: `#!/bin/bash curl -sfL https://get.k3s.io | K3S_URL=https://${master.ipv4Address}:6443 K3S_TOKEN=<your-k3s-token> sh -`, }); const worker2 = new hcloud.Server("k3s-worker-2", { serverType: "cx21", image: "ubuntu-20.04", sshKeys: [sshKey.name], networks: [network.id], firewallIds: [firewall.id], userData: `#!/bin/bash curl -sfL https://get.k3s.io | K3S_URL=https://${master.ipv4Address}:6443 K3S_TOKEN=<your-k3s-token> sh -`, }); // Export the master node's IP address export const masterIp = master.ipv4Address;
This program creates a Hetzner Cloud network, a subnet, a firewall, and three servers (one master and two workers) for the K3s cluster. The master node installs K3s, and the worker nodes join the cluster using the master's IP address and a shared token. Replace
<your-public-ssh-key-here>
and<your-k3s-token>
with your actual SSH public key and K3s token, respectively.