hetznerctl

package
v0.0.0-...-82cfb88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrimaryMaster is the node used to initilize and manage the cluster.
	PrimaryMaster = NodeRole("primary master")
	// BackupMaster nodes are equal to the PrimaryMaster to achieve high availability.
	BackupMaster = NodeRole("backup master")
	// Worker nodes scale the actual cluster.
	Worker = NodeRole("worker")

	// SelectAllNodes is the selector for all nodes.
	SelectAllNodes = "*"
)
View Source
const (
	// RebootKured reboots the node via kured.
	RebootKured = Reboot("kured")
	// RebootKured reboots the node via kured directly.
	RebootKuredRealTime = Reboot("kured-real-time")
	// RebootHardware reboots the node via hetzner robot API resetting the hardware.
	RebootHardware = Reboot(robot.RebootHardware)
	// RebootHardwareUngraceful reboots the node via hetzner robot API resetting the hardware without syncing the disk.
	RebootHardwareUngraceful = Reboot(robot.RebootHardware + "-no-sync")
	// RebootManually reboots the node via hetzner robot API sending a technician.
	RebootManually = Reboot(robot.RebootManually)
	// RebootRescueSystem reboots the node in rescue mode via 'reboot' command.
	RebootRescueSystem = Reboot("rescue-system")
	// RebootSystem reboots the node via 'reboot' command.
	RebootSystem = Reboot("system")

	KuredRebootSentinel = "/var/run/update_engine_autoupdate_completed"

	KuredRebootSentinelRealTime = "/tmp/kured-reboot-required"
)
View Source
const (
	// renovate: datasource=github-tags depName=containernetworking/plugins
	CNI_VERSION = "v1.4.0"

	// renovate: datasource=github-tags depName=kubernetes/kubernetes
	KUBERNETES_VERSION = "v1.28.4"

	// renovate: datasource=github-tags depName=kubernetes/release
	RELEASE_VERSION = "v0.16.4"

	// renovate: datasource=github-tags depName=helm/helm
	HELM_VERSION = "v3.13.2"

	// renovate: datasource=github-tags depName=helmfile/helmfile
	HELMFILE_VERSION = "v0.159.0"

	// renovate: datasource=github-tags depName=kubernetes-sigs/kustomize
	KUSTOMIZE_VERSION = "5.3.0"

	// renovate: datasource=github-tags depName=vmware-tanzu/sonobuoy
	SONOBUOY_VERSION = "v0.57.1"

	// renovate: datasource=github-tags depName=kubernetes-sigs/cri-tools
	CRICTL_VERSION = "v1.28.0"

	// renovate: datasource=github-tags depName=vmware-tanzu/velero
	VELERO_VERSION = "v1.12.2"

	// renovate: datasource=github-tags depName=kubevirt/kubevirt
	VIRTCTL_VERSION = "v1.1.0"

	// renovate: datasource=github-tags depName=utopia-planitia/k8status
	K8STATUS_VERSION = "v0.1.8"
)
View Source
const (
	HELM_RETRIES = 3
)

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath() string

func Dependencies

func Dependencies(w io.Writer, services []string) error

Dependencies prints out the dependencies in dot format. The dependencies are defined per service in dependencies.dot.

func PrintConfig

func PrintConfig(w io.Writer, cfg Config) error

PrintConfig prints the default config template.

func PrintConfigTemplate

func PrintConfigTemplate(w io.Writer) error

PrintConfigTemplate prints the default config template.

func RenderContainerLinuxConfigTemplate

func RenderContainerLinuxConfigTemplate(w io.Writer) error

RenderContainerLinuxConfigTemplate prints the container linux (core os) config template.

Types

type Config

type Config struct {
	SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
	DNSServers        []string `yaml:"dns_servers"`
	NTPServers        []string `yaml:"ntp_servers"`
	VSwitch           struct {
		ID int
	}
	Rescue struct {
		OS   string
		Arch string
	}
	Disks struct {
		OS   string
		Data string
	}
	Flatcar struct {
		InstallScriptUrl string `yaml:"install_script_url"`
		Version          string
		DisableUpdates   bool   `yaml:"disable_updates"`
		UpdateURL        string `yaml:"update_url"`
		BaseURL          string `yaml:"base_url"`
		AppID            string `yaml:"app_id"`
		Group            string
		SignKey          struct {
			URL    string `yaml:"url"`
			SHA256 string `yaml:"sha256"`
		} `yaml:"sign_key"`
	}
	Cloudflare struct {
		Key        string
		Email      string
		Zone       string
		Subdomains struct {
			API  string
			HTTP string
		}
	}
	DockerHub struct {
		Username      string
		Password      string
		DisableViaDns bool `yaml:"disable_via_dns"`
	}
	RegistryMirror struct {
		Endpoint string
		Username string
		Password string
	}
	RegistryMirrorV2 struct {
		Host       string
		Path       string
		PathWithV2 string `yaml:"path_with_v2"`
		Username   string
		Password   string
	} `yaml:"registry_mirror_v2"`
	Hardware struct {
		Disk1    string
		Disk2    string
		DiskType string `yaml:"diskType"`
	}
	Cluster struct {
		Name            string
		Domain          string
		Password        string
		BasicAuth       string `yaml:"basic_auth"`
		MasterNodeCount int    `yaml:"master_node_count"`
		PodsPerNode     int    `yaml:"pods_per_node"`
	}
	Services Services
	Users    []User
	Nodes    Servers
}

Config contains all configurations.

func LoadConfig

func LoadConfig(r io.Reader) (Config, error)

LoadConfig load the config from the reader.

func (Config) APIDomain

func (c Config) APIDomain() string

APIDomain returns the API servers domain without port.

func (Config) ApiserverMemory

func (c Config) ApiserverMemory() int

ApiserverMemory calculates the target memory use for the API Server.

func (Config) KubernetesVersion

func (c Config) KubernetesVersion() string

KubernetesVersion returns the version of Kubernetes.

func (Config) SanityCheck

func (c Config) SanityCheck() error

SanityCheck verifies the config does not contain obvious errors.

func (Config) ToYaml

func (c Config) ToYaml() ([]byte, error)

func (Config) Write

func (c Config) Write() error

func (Config) WriteTo

func (c Config) WriteTo(path string) error

type ContainerLinuxConfig

type ContainerLinuxConfig struct {
	Config
	Node Server
}

ContainerLinuxConfig renders the container linux config template.

type JoinConfiguration

type JoinConfiguration struct {
	Config
	CaCertHashes   string
	Token          string
	CertificateKey string
}

JoinConfiguration renders the join config for kubeadm.

type NodeConfig

type NodeConfig struct {
	Config
	Node Server
}

NodeConfig renders the container linux config template.

type NodeRole

type NodeRole string

NodeRole defines the role of the node.

type Patches

type Patches struct {
	Etcd struct {
		Request struct {
			CPU    string
			Memory string
		}
		Limit struct {
			CPU    string
			Memory string
		}
	}
	APIServer struct {
		Request struct {
			CPU    string
			Memory string
		}
		Limit struct {
			CPU    string
			Memory string
		}
	}
	ControllerManager struct {
		Request struct {
			CPU    string
			Memory string
		}
		Limit struct {
			CPU    string
			Memory string
		}
	}
	Scheduler struct {
		Request struct {
			CPU    string
			Memory string
		}
		Limit struct {
			CPU    string
			Memory string
		}
	}
}

Patches represents the changes applied to etcd, apiserver, controller-manager, and scheduler.

type Reboot

type Reboot string

Reboot defines who to reboot a server.

type Server

type Server struct {
	Name    string
	Hetzner struct {
		Username string
		Password string
	}
	Role    NodeRole
	Network struct {
		IPv6       string
		PublicIP   string `yaml:"public_ip"`
		Gateway    string
		PrivateIP  string `yaml:"private_ip"`
		MAC        string
		DeviceName string `yaml:"device_name"`
	}
}

Server represents a node of the cluster.

func (Server) AnnotateNodes

func (s Server) AnnotateNodes(cfg Config) error

AnnotateNodes adds annotations to the nodes.

func (Server) Apply

func (s Server) Apply(yaml []byte, delete bool, namespace string) error

Apply applies manifests to the setup. Yaml strings are used as they are.

func (Server) ApplyServices

func (s Server) ApplyServices(cfg Config, services []string, delete, verbose bool, tries int, selectors []string) error

func (Server) ApplyTpl

func (s Server) ApplyTpl(yaml []byte, delete bool, namespace string, cfg *Config) error

ApplyTpl applies rendered manifests to the setup. Yaml strings are used as templates and rendered before being applied.

func (Server) AwaitDNS

func (s Server) AwaitDNS(domain string) error

AwaitDNS deploys cilium connectivity check.

func (Server) BootRescueMode

func (s Server) BootRescueMode(cfg Config) error

BootRescueMode reboots into rescue mode and installs SSH keys.

func (Server) ConfigureFlatcar

func (s Server) ConfigureFlatcar(cfg Config) error

IgnitionConfigUpdate updates the ignition config, marks the config to be recompressed, and triggers a reboot via kured.

func (Server) ConfigureSSHKeys

func (s Server) ConfigureSSHKeys(cfg Config) error

ConfigureSSHKeys prepares node to be accessible via ssh.

func (Server) CreateUsers

func (s Server) CreateUsers(cfg Config) error

CreateUsers creates and enabled/disables cluster role bindings.

func (Server) DeployServices

func (s Server) DeployServices(cfg Config, services []string, delete, verbose bool, tries int) error

func (Server) Exec

func (s Server) Exec(args []string) error

Exec runs a command on the remote server.

func (Server) FinalizeMaintenance

func (s Server) FinalizeMaintenance(c Config) error

FinalizeMaintenance is a hook to end maintenance.

func (Server) InitCluster

func (s Server) InitCluster(cfg Config) error

InitCluster creates a new cluster on the node. The node becomes the first master node.

func (Server) InstallFlatcar

func (s Server) InstallFlatcar(cfg Config) error

InstallFlatcar executes the official flatcar os installer to install flatcar. The installer is downloaded and the rendered igition config is uploaded as a preparation.

func (Server) KubeConfig

func (s Server) KubeConfig(w io.Writer, cfg Config) error

KubeConfig prints the admin kube config generated by kubeadm.

func (Server) KubernetesStatus

func (s Server) KubernetesStatus() error

KubernetesStatus prints the status of kubernetes.

func (Server) KuredStatus

func (s Server) KuredStatus(sentinel string) (bool, error)

KuredStatus prints kured status.

func (Server) Log

func (s Server) Log(f string, a ...interface{})

Log prints messages prefixed with the servers name.

func (Server) NodesStatus

func (s Server) NodesStatus() error

NodesStatus prints the node status known to kubernetes.

func (Server) PatchAPIService

func (s Server) PatchAPIService(cfg Config) error

PatchAPIService avoids connection drops via session stickiness.

func (Server) PrepareMaintenance

func (s Server) PrepareMaintenance(c Config) error

PrepareMaintenance is a hook to begin maintenance.

func (Server) Reboot

func (s Server) Reboot(rst Reboot) error

Reboot reboots the node.

func (Server) RebootToSSH

func (s Server) RebootToSSH(rst Reboot) error

RebootToSSH triggers a reboots and waits until port 22 (ssh) opened.

func (Server) RenderContainerLinuxConfig

func (s Server) RenderContainerLinuxConfig(cfg Config) ([]byte, error)

RenderContainerLinuxConfig prints the container linux (core os) config.

func (Server) RenderIgnitionConfig

func (s Server) RenderIgnitionConfig(cfg Config) ([]byte, error)

RenderIgnitionConfig prints the ignition config.

func (Server) ResetKubeadm

func (s Server) ResetKubeadm() error

ResetKubeadm uses kubeadm to reset kubernetes.

func (Server) RestartService

func (s Server) RestartService(svc string) error

RestartService restarts the given services by calling systemctl.

func (Server) RobotNode

func (s Server) RobotNode() robot.Server

RobotNode creates access hetzner robot API.

func (Server) SetupAddons

func (s Server) SetupAddons(cfg Config, delete, verbose bool, tries int) error

func (Server) SetupFlatcar

func (s Server) SetupFlatcar(cfg Config) error

SetupFlatcar installs flatcar os.

func (Server) Sonobuoy

func (s Server) Sonobuoy() error

func (Server) TestServices

func (s Server) TestServices(cfg Config, services []string, verbose, sync bool, reties int, filter string) error

func (Server) UptimeStatus

func (s Server) UptimeStatus() error

UptimeStatus prints the uptime.

func (Server) UserKubeConfig

func (s Server) UserKubeConfig(w io.Writer, cfg Config, user string) error

UserKubeConfig prints the user's kube config generated by kubeadm.

type Servers

type Servers []Server

Servers represents the nodes of the cluster.

func (Servers) BootRescueMode

func (ss Servers) BootRescueMode(cfg Config) error

BootRescueMode reboots all nodes into rescue mode.

func (Servers) ConfigureFlatcar

func (ss Servers) ConfigureFlatcar(cfg Config) error

ConfigureFlatcar updates each node by rerunning ignition.

func (Servers) ConfigureSSHKeys

func (ss Servers) ConfigureSSHKeys(cfg Config) error

ConfigureSSHKeys prepares all nodes to be accessible via ssh.

func (Servers) Count

func (ss Servers) Count() int

Count counts the nodes.

func (Servers) DeleteDataDisk

func (ss Servers) DeleteDataDisk(cfg Config) error

DeleteDataDisk empties the data disk on all nodes.

func (Servers) DisableFirewall

func (ss Servers) DisableFirewall() error

DisableFirewall disables the firewall of each node.

func (Servers) DisableRescueMode

func (ss Servers) DisableRescueMode() error

DisableRescueMode disable the rescue mode of each node.

func (Servers) EnableFirewall

func (ss Servers) EnableFirewall() error

EnableFirewall enables the firewall of each node.

func (Servers) EnableRescueMode

func (ss Servers) EnableRescueMode(cfg Config) error

EnableRescueMode enables the rescue mode of each node.

func (Servers) EtcHosts

func (ss Servers) EtcHosts(w io.Writer) error

EtcHosts prints the /etc/hosts entries to access the nodes without dns entries.

func (Servers) Exec

func (ss Servers) Exec(args []string, abortOnFailure bool) error

Exec runs a command for each server.

func (Servers) Filter

func (ss Servers) Filter(nodeSelection string) Servers

Filter selects the nodes of a role type.

func (Servers) FirewallStatus

func (ss Servers) FirewallStatus() error

FirewallStatus prints the firewall status of each node.

func (Servers) InstallFlatcar

func (ss Servers) InstallFlatcar(cfg Config) error

InstallFlatcar installs flatcar os on each node using the official installer.

func (Servers) JoinMasters

func (ss Servers) JoinMasters(primaryMaster Server, cfg Config) error

JoinMasters joins the nodes as a masters to the cluster.

func (Servers) JoinWorker

func (ss Servers) JoinWorker(master Server, cfg Config) error

JoinWorker joins the node as a worker to the cluster.

func (Servers) KubeadmUpdate

func (ss Servers) KubeadmUpdate(cfg Config, skipDrain, skipAwaitReady, verbose bool) error

KubeadmUpdate updates the clusters following the instructions at https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/

func (Servers) KuredStatus

func (ss Servers) KuredStatus(sentinel string) (bool, error)

KuredStatus prints kured status for each server.

func (Servers) MastersCount

func (ss Servers) MastersCount() int

MastersCount counts the masters.

func (Servers) NonePrimaryMaster

func (ss Servers) NonePrimaryMaster() Servers

NonePrimaryMaster selects backups master and worker nodes.

func (Servers) PrimaryMaster

func (ss Servers) PrimaryMaster() (Server, error)

PrimaryMaster returns the primary master.

func (Servers) Reboot

func (ss Servers) Reboot(rst Reboot) error

Reboot reboots all nodes.

func (Servers) RebootHardware

func (ss Servers) RebootHardware() error

func (Servers) RebootHardwareUngraceful

func (ss Servers) RebootHardwareUngraceful() error

func (Servers) RebootKured

func (ss Servers) RebootKured() error

func (Servers) RebootKuredRealTime

func (ss Servers) RebootKuredRealTime() error

func (Servers) RebootManually

func (ss Servers) RebootManually() error

func (Servers) RebootRescueSystem

func (ss Servers) RebootRescueSystem() error

func (Servers) RebootSystem

func (ss Servers) RebootSystem() error

func (Servers) RebootToSSH

func (ss Servers) RebootToSSH(rst Reboot) error

RebootToSSH reboots all nodes and waits until port 22 (ssh) opened.

func (Servers) RenderContainerLinuxConfig

func (ss Servers) RenderContainerLinuxConfig(cfg Config, w io.Writer) error

RenderContainerLinuxConfig prints the container linux (core os) config for each node.

func (Servers) RenderIgnitionConfig

func (ss Servers) RenderIgnitionConfig(cfg Config, w io.Writer) error

RenderIgnitionConfig prints the ignition config for each node.

func (Servers) RescueModeOptions

func (ss Servers) RescueModeOptions() error

RescueModeStatus prints the rescue mode status of each node.

func (Servers) RescueModePassword

func (ss Servers) RescueModePassword() error

RescueModePassword prints the rescue mode password of each node.

func (Servers) RescueModeStatus

func (ss Servers) RescueModeStatus() error

RescueModeStatus prints the rescue mode status of each node.

func (Servers) ResetKubeadm

func (ss Servers) ResetKubeadm() error

ResetKubeadm uses kubeadm to reset kubernetes on each node.

func (Servers) RestartService

func (ss Servers) RestartService(svc string) error

RestartService restarts the given services on each node.

func (Servers) SSHConfig

func (ss Servers) SSHConfig(w io.Writer, disableHostkeyChecking bool) error

SSHConfig prints the ssh config to access the nodes via ssh. The content is meant to be placed in ~/.ssh/config.

func (Servers) SSHKeyscan

func (ss Servers) SSHKeyscan(w io.Writer) error

SSHKeyscan prints the command to scan ssh fingerprints for each node.

func (Servers) SelectBackupMasters

func (ss Servers) SelectBackupMasters() Servers

SelectBackupMasters selects the backup master nodes.

func (Servers) SelectMasters

func (ss Servers) SelectMasters() Servers

SelectMasters selects the master nodes.

func (Servers) SelectPrimaryMasters

func (ss Servers) SelectPrimaryMasters() Servers

SelectPrimaryMasters selects the backup master nodes.

func (Servers) SelectWorkers

func (ss Servers) SelectWorkers() Servers

SelectWorkers selects the worker nodes.

func (Servers) SetupFlatcar

func (ss Servers) SetupFlatcar(cfg Config) error

SetupFlatcar installs the operating system on all nodes.

func (Servers) SetupKubeadm

func (ss Servers) SetupKubeadm(cfg Config, verbose bool, helmfileSyncTries int) error

SetupKubeadm installs kubernetes on the nodes. First the primary master is created, then the addons are installed, the backup masters join serially, and then the worker nodes join.

func (Servers) Uncordon

func (ss Servers) Uncordon(master Server) error

Uncordon uncordons all nodes.

func (Servers) UptimeStatus

func (ss Servers) UptimeStatus() error

UptimeStatus prints the uptime for each server.

type Services

type Services struct {
	Minio struct {
		AccessKey string `yaml:"access_key"`
		SecretKey string `yaml:"secret_key"`
		Backup    struct {
			Cron      string
			Enabled   bool
			Host      string
			AccessKey string `yaml:"access_key"`
			SecretKey string `yaml:"secret_key"`
			Directory string
		}
	}
	Cassandra struct {
		Backups []struct {
			Keyspace string
			Cron     string
			Enabled  bool
		}
	}
	Kured struct {
		RebootSentinel string `yaml:"reboot_sentinel"`
		StartTime      string `yaml:"start_time"`
		EndTime        string `yaml:"end_time"`
		Period         string `yaml:"period"`
	}
	Registry struct {
		ServiceIP string `yaml:"service_ip"`
		Secret    string
	}
}

Services configures the services via templates in .yaml.tpl files.

type User

type User struct {
	Name      string
	Role      string
	Namespace string
	Active    bool
}

User represents a kubectl user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL