Install using k0sctl

k0sctl is a command-line tool for bootstrapping and managing k0s clusters. k0sctl connects to the provided hosts using SSH and gathers information on the hosts, with which it forms a cluster by configuring the hosts, deploying k0s, and then connecting the k0s nodes together.

k0sctl deployment

With k0sctl, you can create multi-node clusters in a manner that is automatic and easily repeatable. This method is recommended for production cluster installation.

Note: The k0sctl install method is necessary for automatic upgrade.

Prerequisites

You can execute k0sctl on any system that supports the Go language. Pre-compiled k0sctl binaries are available on the k0sctl releases page).

Note: For target host prerequisites information, refer to the k0s System Requirements.

Install k0s

1. Install k0sctl tool

k0sctl is a single binary, the instructions for downloading and installing of which are available in the k0sctl github repository.

2. Configure the cluster

  1. Run the following command to create a k0sctl configuration file:

    1. k0sctl init > k0sctl.yaml

    This action creates a k0sctl.yaml file in the current directory:

    1. apiVersion: k0sctl.k0sproject.io/v1beta1
    2. kind: Cluster
    3. metadata:
    4. name: k0s-cluster
    5. spec:
    6. hosts:
    7. - role: controller
    8. ssh:
    9. address: 10.0.0.1 # replace with the controller's IP address
    10. user: root
    11. keyPath: ~/.ssh/id_rsa
    12. - role: worker
    13. ssh:
    14. address: 10.0.0.2 # replace with the worker's IP address
    15. user: root
    16. keyPath: ~/.ssh/id_rsa
  2. Provide each host with a valid IP address that is reachable by k0sctl, and the connection details for an SSH connection.

Note: Refer to the k0sctl documentation for k0sctl configuration specifications.

3. Deploy the cluster

Run k0sctl apply to perform the cluster deployment:

  1. k0sctl apply --config k0sctl.yaml
  1. ⠀⣿⣿⡇⠀⠀⢀⣴⣾⣿⠟⠁⢸⣿⣿⣿⣿⣿⣿⣿⡿⠛⠁⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀█████████ █████████ ███
  2. ⠀⣿⣿⡇⣠⣶⣿⡿⠋⠀⠀⠀⢸⣿⡇⠀⠀⠀⣠⠀⠀⢀⣠⡆⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀███ ███ ███
  3. ⠀⣿⣿⣿⣿⣟⠋⠀⠀⠀⠀⠀⢸⣿⡇⠀⢰⣾⣿⠀⠀⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀███ ███ ███
  4. ⠀⣿⣿⡏⠻⣿⣷⣤⡀⠀⠀⠀⠸⠛⠁⠀⠸⠋⠁⠀⠀⣿⣿⡇⠈⠉⠉⠉⠉⠉⠉⠉⠉⢹⣿⣿⠀███ ███ ███
  5. ⠀⣿⣿⡇⠀⠀⠙⢿⣿⣦⣀⠀⠀⠀⣠⣶⣶⣶⣶⣶⣶⣿⣿⡇⢰⣶⣶⣶⣶⣶⣶⣶⣶⣾⣿⣿⠀█████████ ███ ██████████
  6. INFO k0sctl 0.0.0 Copyright 2021, Mirantis Inc.
  7. INFO Anonymized telemetry will be sent to Mirantis.
  8. INFO By continuing to use k0sctl you agree to these terms:
  9. INFO https://k0sproject.io/licenses/eula
  10. INFO ==> Running phase: Connect to hosts
  11. INFO [ssh] 10.0.0.1:22: connected
  12. INFO [ssh] 10.0.0.2:22: connected
  13. INFO ==> Running phase: Detect host operating systems
  14. INFO [ssh] 10.0.0.1:22: is running Ubuntu 20.10
  15. INFO [ssh] 10.0.0.2:22: is running Ubuntu 20.10
  16. INFO ==> Running phase: Prepare hosts
  17. INFO [ssh] 10.0.0.1:22: installing kubectl
  18. INFO ==> Running phase: Gather host facts
  19. INFO [ssh] 10.0.0.1:22: discovered 10.12.18.133 as private address
  20. INFO ==> Running phase: Validate hosts
  21. INFO ==> Running phase: Gather k0s facts
  22. INFO ==> Running phase: Download K0s on the hosts
  23. INFO [ssh] 10.0.0.2:22: downloading k0s 0.11.0
  24. INFO [ssh] 10.0.0.1:22: downloading k0s 0.11.0
  25. INFO ==> Running phase: Configure K0s
  26. WARN [ssh] 10.0.0.1:22: generating default configuration
  27. INFO [ssh] 10.0.0.1:22: validating configuration
  28. INFO [ssh] 10.0.0.1:22: configuration was changed
  29. INFO ==> Running phase: Initialize K0s Cluster
  30. INFO [ssh] 10.0.0.1:22: installing k0s controller
  31. INFO [ssh] 10.0.0.1:22: waiting for the k0s service to start
  32. INFO [ssh] 10.0.0.1:22: waiting for kubernetes api to respond
  33. INFO ==> Running phase: Install workers
  34. INFO [ssh] 10.0.0.1:22: generating token
  35. INFO [ssh] 10.0.0.2:22: writing join token
  36. INFO [ssh] 10.0.0.2:22: installing k0s worker
  37. INFO [ssh] 10.0.0.2:22: starting service
  38. INFO [ssh] 10.0.0.2:22: waiting for node to become ready
  39. INFO ==> Running phase: Disconnect from hosts
  40. INFO ==> Finished in 2m2s
  41. INFO k0s cluster version 0.11.0 is now installed
  42. INFO Tip: To access the cluster you can now fetch the admin kubeconfig using:
  43. INFO k0sctl kubeconfig

4. Access the cluster

To access your k0s cluster, use k0sctl to generate a kubeconfig for the purpose.

  1. k0sctl kubeconfig > kubeconfig

With the kubeconfig, you can access your cluster using either kubectl or Lens.

  1. kubectl get pods --kubeconfig kubeconfig -A
  1. NAMESPACE NAME READY STATUS RESTARTS AGE
  2. kube-system calico-kube-controllers-5f6546844f-w8x27 1/1 Running 0 3m50s
  3. kube-system calico-node-vd7lx 1/1 Running 0 3m44s
  4. kube-system coredns-5c98d7d4d8-tmrwv 1/1 Running 0 4m10s
  5. kube-system konnectivity-agent-d9xv2 1/1 Running 0 3m31s
  6. kube-system kube-proxy-xp9r9 1/1 Running 0 4m4s
  7. kube-system metrics-server-6fbcd86f7b-5frtn 1/1 Running 0 3m51s

Known limitations

  • k0sctl does not perform any discovery of hosts, and thus it only operates on the hosts listed in the provided configuration.
  • k0sctl can only add more nodes to the cluster. It cannot remove existing nodes.

Next Steps