Download the k0s binary

Prerequisites

Before proceeding, make sure to review the System Requirements

K0s Download Script

  1. $ curl -sSLf https://get.k0s.sh | sudo sh

The download script accepts the following environment variables:

  1. K0S_VERSION=v0.11.0 - select the version of k0s to be installed
  2. DEBUG=true - outputs commands and their arguments as they are executed.

Installing k0s as a service on the local system

The k0s install sub-command will install k0s as a system service on hosts running one of the supported init systems: Systemd or OpenRC.

Install can be executed for workers, controllers or single node (controller+worker) instances.

The install controller sub-command accepts the same flags and parameters as the k0s controller sub-command does.

  1. $ k0s install controller --help
  2. Helper command for setting up k0s as controller node on a brand-new system. Must be run as root (or with sudo)
  3. Usage:
  4. k0s install controller [flags]
  5. Aliases:
  6. controller, server
  7. Examples:
  8. All default values of controller command will be passed to the service stub unless overriden.
  9. With controller subcommand you can setup a single node cluster by running:
  10. k0s install controller --enable-worker
  11. Flags:
  12. -c, --config string config file (default: ./k0s.yaml)
  13. --cri-socket string contrainer runtime socket to use, default to internal containerd. Format: [remote|docker]:[path-to-socket]
  14. -d, --debug Debug logging (default: false)
  15. --enable-worker enable worker (default false)
  16. -h, --help help for controller
  17. -l, --logging stringToString Logging Levels for the different components (default [konnectivity-server=1,kube-apiserver=1,kube-controller-manager=1,kube-scheduler=1,kubelet=1,kube-proxy=1,etcd=info,containerd=info])
  18. --profile string worker profile to use on the node (default "default")
  19. --token-file string Path to the file containing join-token.
  20. Global Flags:
  21. --data-dir string Data Directory for k0s (default: /var/lib/k0s). DO NOT CHANGE for an existing setup, things will break!
  22. --debugListenOn string Http listenOn for debug pprof handler (default ":6060")

For example, the command below will install a single node k0s service on Ubuntu 20.10:

  1. $ k0s install controller --enable-worker
  2. INFO[2021-02-24 11:05:42] no config file given, using defaults
  3. INFO[2021-02-24 11:05:42] creating user: etcd
  4. INFO[2021-02-24 11:05:42] creating user: kube-apiserver
  5. INFO[2021-02-24 11:05:42] creating user: konnectivity-server
  6. INFO[2021-02-24 11:05:42] creating user: kube-scheduler
  7. INFO[2021-02-24 11:05:42] Installing k0s service

Run k0s as a service

  1. $ systemctl start k0scontroller

Check service status

  1. $ systemctl status k0scontroller
  2. Loaded: loaded (/etc/systemd/system/k0scontroller.service; enabled; vendor preset: enabled)
  3. Active: active (running) since Fri 2021-02-26 08:37:23 UTC; 1min 25s ago
  4. Docs: https://docs.k0sproject.io
  5. Main PID: 1408647 (k0s)
  6. Tasks: 96
  7. Memory: 1.2G
  8. CGroup: /system.slice/k0scontroller.service
  9. ....

Query cluster status

  1. $ k0s status
  2. Version: v0.11.0-beta.2-16-g02cddab
  3. Process ID: 9322
  4. Parent Process ID: 1
  5. Role: controller+worker
  6. Init System: linux-systemd

Fetch nodes

  1. $ k0s kubectl get nodes
  2. NAME STATUS ROLES AGE VERSION
  3. k0s Ready <none> 4m6s v1.20.4-k0s1

Enabling Shell Completion

The k0s completion script for Bash, zsh, fish and powershell can be generated with the command k0s completion < shell >. Sourcing the completion script in your shell enables k0s autocompletion.

Bash

  1. echo 'source <(k0s completion bash)' >>~/.bashrc
  1. # To load completions for each session, execute once:
  2. $ k0s completion bash > /etc/bash_completion.d/k0s

Zsh

If shell completion is not already enabled in your environment you will need to enable it. You can execute the following once:

  1. $ echo "autoload -U compinit; compinit" >> ~/.zshrc
  1. # To load completions for each session, execute once:
  2. $ k0s completion zsh > "${fpath[1]}/_k0s"

You will need to start a new shell for this setup to take effect.

Fish

  1. $ k0s completion fish | source
  1. # To load completions for each session, execute once:
  2. $ k0s completion fish > ~/.config/fish/completions/k0s.fish

Under the hood

Workers are always run as root. For controllers, the command will create the following system users: etcd, kube-apiserver, konnectivity-server, kube-scheduler

Additional Documentation

see: k0s install