Installation script options

As mentioned in the Quick-Start Guide, you can use the installation script available at https://get.k3s.io to install K3s as a service on systemd and openrc based systems.

The simplest form of this command is as follows:

  1. curl -sfL https://get.k3s.io | sh -

When using this method to install K3s, the following environment variables can be used to configure the installation:

  • INSTALL_K3S_SKIP_DOWNLOAD

If set to true will not download K3s hash or binary.

  • INSTALL_K3S_SYMLINK

If set to ‘skip’ will not create symlinks, ‘force’ will overwrite, default will symlink if command does not exist in path.

  • INSTALL_K3S_SKIP_START

If set to true will not start K3s service.

  • INSTALL_K3S_VERSION

Version of K3s to download from github. Will attempt to download the latest version if not specified.

  • INSTALL_K3S_BIN_DIR

Directory to install K3s binary, links, and uninstall script to, or use /usr/local/bin as the default.

  • INSTALL_K3S_BIN_DIR_READ_ONLY

If set to true will not write files to INSTALL_K3S_BIN_DIR, forces setting INSTALL_K3S_SKIP_DOWNLOAD=true.

  • INSTALL_K3S_SYSTEMD_DIR

Directory to install systemd service and environment files to, or use /etc/systemd/system as the default.

  • INSTALL_K3S_EXEC

Command with flags to use for launching K3s in the service. If the command is not specified, it will default to “agent” if K3S_URL is set or “server” if it is not set. The final systemd command resolves to a combination of this environment variable and script args. To illustrate this, the following commands result in the same behavior:

  1. curl ... | INSTALL_K3S_EXEC="--no-flannel" sh -s -
  2. curl ... | INSTALL_K3S_EXEC="server --no-flannel" sh -s -
  3. curl ... | INSTALL_K3S_EXEC="server" sh -s - --no-flannel
  4. curl ... | sh -s - server --no-flannel
  5. curl ... | sh -s - --no-flannel
  • INSTALL_K3S_NAMEName of systemd service to create, will default from the K3s exec command if not specified. If specified the name will be prefixed with ‘k3s-’.

  • INSTALL_K3S_TYPEType of systemd service to create, will default from the K3s exec command if not specified.

Environment variables which begin with K3S_ will be preserved for the systemd and openrc services to use. Setting K3S_URL without explicitly setting an exec command will default the command to “agent”. When running the agent K3S_TOKEN must also be set.

Beyond the Installation Script

As stated, the installation script is primarily concerned with configuring K3s to run as a service. If you choose to not use the script, you can run K3s simply by downloading the binary from our release page, placing it on your path, and executing it. The K3s binary supports the following commands:

CommandDescription
k3s serverRun the K3s management server, which will also launch Kubernetes control plane components such as the API server, controller-manager, and scheduler.
k3s agentRun the K3s node agent. This will cause K3s to run as a worker node, launching the Kubernetes node services kubelet and kube-proxy.
k3s kubectlRun an embedded kubectl CLI. If the KUBECONFIG environment variable is not set, this will automatically attempt to use the config file that is created at /etc/rancher/k3s/k3s.yaml when launching a K3s server node.
k3s crictlRun an embedded crictl. This is a CLI for interacting with Kubernetes’s container runtime interface (CRI). Useful for debugging.
k3s ctrRun an embedded ctr. This is a CLI for containerd, the container daemon used by K3s. Useful for debugging.
k3s helpShows a list of commands or help for one command

The k3s server and k3s agent commands have additional configuration options that can be viewed with k3s server —help or k3s agent —help. For convenience, that help text is presented here:

k3s server

  1. NAME:
  2. k3s server - Run management server
  3. USAGE:
  4. k3s server [OPTIONS]
  5. OPTIONS:
  6. -v value (logging) Number for the log level verbosity (default: 0)
  7. --vmodule value (logging) Comma-separated list of pattern=N settings for file-filtered logging
  8. --log value, -l value (logging) Log to file
  9. --alsologtostderr (logging) Log to standard error as well as file (if set)
  10. --bind-address value (listener) k3s bind address (default: 0.0.0.0)
  11. --https-listen-port value (listener) HTTPS listen port (default: 6443)
  12. --advertise-address value (listener) IP address that apiserver uses to advertise to members of the cluster (default: node-external-ip/node-ip)
  13. --advertise-port value (listener) Port that apiserver uses to advertise to members of the cluster (default: listen-port) (default: 0)
  14. --tls-san value (listener) Add additional hostname or IP as a Subject Alternative Name in the TLS cert
  15. --data-dir value, -d value (data) Folder to hold state default /var/lib/rancher/k3s or ${HOME}/.rancher/k3s if not root
  16. --cluster-cidr value (networking) Network CIDR to use for pod IPs (default: "10.42.0.0/16")
  17. --service-cidr value (networking) Network CIDR to use for services IPs (default: "10.43.0.0/16")
  18. --cluster-dns value (networking) Cluster IP for coredns service. Should be in your service-cidr range (default: 10.43.0.10)
  19. --cluster-domain value (networking) Cluster Domain (default: "cluster.local")
  20. --flannel-backend value (networking) One of 'none', 'vxlan', 'ipsec', or 'flannel' (default: "vxlan")
  21. --token value, -t value (cluster) Shared secret used to join a server or agent to a cluster [$K3S_TOKEN]
  22. --token-file value (cluster) File containing the cluster-secret/token [$K3S_TOKEN_FILE]
  23. --write-kubeconfig value, -o value (client) Write kubeconfig for admin client to this file [$K3S_KUBECONFIG_OUTPUT]
  24. --write-kubeconfig-mode value (client) Write kubeconfig with this mode [$K3S_KUBECONFIG_MODE]
  25. --kube-apiserver-arg value (flags) Customized flag for kube-apiserver process
  26. --kube-scheduler-arg value (flags) Customized flag for kube-scheduler process
  27. --kube-controller-manager-arg value (flags) Customized flag for kube-controller-manager process
  28. --kube-cloud-controller-manager-arg value (flags) Customized flag for kube-cloud-controller-manager process
  29. --datastore-endpoint value (db) Specify etcd, Mysql, Postgres, or Sqlite (default) data source name [$K3S_DATASTORE_ENDPOINT]
  30. --datastore-cafile value (db) TLS Certificate Authority file used to secure datastore backend communication [$K3S_DATASTORE_CAFILE]
  31. --datastore-certfile value (db) TLS certification file used to secure datastore backend communication [$K3S_DATASTORE_CERTFILE]
  32. --datastore-keyfile value (db) TLS key file used to secure datastore backend communication [$K3S_DATASTORE_KEYFILE]
  33. --default-local-storage-path value (storage) Default local storage path for local provisioner storage class
  34. --no-deploy value (components) Do not deploy packaged components (valid items: coredns, servicelb, traefik, local-storage, metrics-server)
  35. --disable-scheduler (components) Disable Kubernetes default scheduler
  36. --disable-cloud-controller (components) Disable k3s default cloud controller manager
  37. --disable-network-policy (components) Disable k3s default network policy controller
  38. --node-name value (agent/node) Node name [$K3S_NODE_NAME]
  39. --with-node-id (agent/node) Append id to node name
  40. --node-label value (agent/node) Registering kubelet with set of labels
  41. --node-taint value (agent/node) Registering kubelet with set of taints
  42. --docker (agent/runtime) Use docker instead of containerd
  43. --container-runtime-endpoint value (agent/runtime) Disable embedded containerd and use alternative CRI implementation
  44. --pause-image value (agent/runtime) Customized pause image for containerd sandbox
  45. --private-registry value (agent/runtime) Private registry configuration file (default: "/etc/rancher/k3s/registries.yaml")
  46. --node-ip value, -i value (agent/networking) IP address to advertise for node
  47. --node-external-ip value (agent/networking) External IP address to advertise for node
  48. --resolv-conf value (agent/networking) Kubelet resolv.conf file [$K3S_RESOLV_CONF]
  49. --flannel-iface value (agent/networking) Override default flannel interface
  50. --flannel-conf value (agent/networking) Override default flannel config file
  51. --kubelet-arg value (agent/flags) Customized flag for kubelet process
  52. --kube-proxy-arg value (agent/flags) Customized flag for kube-proxy process
  53. --rootless (experimental) Run rootless
  54. --agent-token value (experimental/cluster) Shared secret used to join agents to the cluster, but not servers [$K3S_AGENT_TOKEN]
  55. --agent-token-file value (experimental/cluster) File containing the agent secret [$K3S_AGENT_TOKEN_FILE]
  56. --server value, -s value (experimental/cluster) Server to connect to, used to join a cluster [$K3S_URL]
  57. --cluster-init (experimental/cluster) Initialize new cluster master [$K3S_CLUSTER_INIT]
  58. --cluster-reset (experimental/cluster) Forget all peers and become a single cluster new cluster master [$K3S_CLUSTER_RESET]
  59. --no-flannel (deprecated) use --flannel-backend=none
  60. --cluster-secret value (deprecated) use --token [$K3S_CLUSTER_SECRET]

k3s agent

  1. NAME:
  2. k3s agent - Run node agent
  3. USAGE:
  4. k3s agent [OPTIONS]
  5. OPTIONS:
  6. -v value (logging) Number for the log level verbosity (default: 0)
  7. --vmodule value (logging) Comma-separated list of pattern=N settings for file-filtered logging
  8. --log value, -l value (logging) Log to file
  9. --alsologtostderr (logging) Log to standard error as well as file (if set)
  10. --token value, -t value (cluster) Token to use for authentication [$K3S_TOKEN]
  11. --token-file value (cluster) Token file to use for authentication [$K3S_TOKEN_FILE]
  12. --server value, -s value (cluster) Server to connect to [$K3S_URL]
  13. --data-dir value, -d value (agent/data) Folder to hold state (default: "/var/lib/rancher/k3s")
  14. --node-name value (agent/node) Node name [$K3S_NODE_NAME]
  15. --with-node-id (agent/node) Append id to node name
  16. --node-label value (agent/node) Registering kubelet with set of labels
  17. --node-taint value (agent/node) Registering kubelet with set of taints
  18. --docker (agent/runtime) Use docker instead of containerd
  19. --container-runtime-endpoint value (agent/runtime) Disable embedded containerd and use alternative CRI implementation
  20. --pause-image value (agent/runtime) Customized pause image for containerd sandbox
  21. --private-registry value (agent/runtime) Private registry configuration file (default: "/etc/rancher/k3s/registries.yaml")
  22. --node-ip value, -i value (agent/networking) IP address to advertise for node
  23. --node-external-ip value (agent/networking) External IP address to advertise for node
  24. --resolv-conf value (agent/networking) Kubelet resolv.conf file [$K3S_RESOLV_CONF]
  25. --flannel-iface value (agent/networking) Override default flannel interface
  26. --flannel-conf value (agent/networking) Override default flannel config file
  27. --kubelet-arg value (agent/flags) Customized flag for kubelet process
  28. --kube-proxy-arg value (agent/flags) Customized flag for kube-proxy process
  29. --rootless (experimental) Run rootless
  30. --no-flannel (deprecated) use --flannel-backend=none
  31. --cluster-secret value (deprecated) use --token [$K3S_CLUSTER_SECRET]