Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a requirement and installation doc for K3s #1624

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added content/en/hosting/image.png
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image is too small to be useful and I can't tell what it is. If you'd like to keep it, please move it to the new location under production 4.x k8s directory, make it higher resolution and ensure it's applicable for how to install CHT Core on k3s (and not a generic k3s architecture diagram).

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 159 additions & 0 deletions content/en/hosting/install-k3s.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
title: "Install K3s"
weight: 4
description: >
Setup K3s
---
## Introduction

[K3s](https://k3s.io/?ref=traefik.io) is a lightweight Kubernetes distribution. Easy to install, half the memory, all in a binary of less than 100 MB. K3s is highly available and production-ready and very low resource requirements.
Great for:

* Edge
* IoT
* CI
* Development
* ARM
* Embedding k8s
* Situations where a PhD in k8s clusterology is infeasible

## Architecture

### Servers and Agents

* A server node is defined as a host running the k3s server command, with control-plane and datastore components managed by K3s.
* An agent node is defined as a host running the k3s agent command, without any datastore or control-plane components.
* Both servers and agents run the kubelet, container runtime, and CNI.

![alt text](image.png)

## Configuration Options

K3s offers a variety of configuration options to tailor the setup to your needs.
Here are some key options:

### Basic Configuration Options

#### **Installation Script**

Use the installation script to set up K3s as a service and by using the installation script we install K3s as systemd and openrc based systems.

To install K3s using the installation script, follow these steps:

1. **Download the Installation Script** :

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

This command downloads the script and runs it, installing K3s as a service on your system1.

1. **Verify the Installation** :

```
k3s kubectl get nodes
```

This command checks if K3s is running and lists the nodes in your cluster.

1. **Additional Utilities** :

* The script also installs additional utilities like `kubectl`, `crictl`, `ctr`, `k3s-killall.sh`, and `k3s-uninstall.sh`1.

1. **Configuration Options** :

* You can use environment variables prefixed with `K3S_` or pass command flags to configure K3s2.
* For example, to set the server address:
**sh**Copy

```
exportK3S_SERVER=https://your-server-address:6443
curl -sfL https://get.k3s.io | sh -
```

1. **Edit Configuration** :

* After installation, you can edit the service configuration or environment file to change settings.
* A [kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) file will be written to `/etc/rancher/k3s/k3s.yaml` and the kubectl installed by K3s will automatically use it
* You can use a combination of `INSTALL_K3S_EXEC`, `K3S_` environment variables, and command flags to pass configuration to the service configuration. The prefixed environment variables, `INSTALL_K3S_EXEC` value, and trailing shell arguments are all persisted into the service configuration. After installation, configuration may be altered by editing the environment file, editing the service configuration, or simply re-running the installer with new options.

```
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" sh -s - --flannel-backend none --token 12345
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --flannel-backend none" K3S_TOKEN=12345 sh -s -
curl -sfL https://get.k3s.io | K3S_TOKEN=12345 sh -s - server --flannel-backend none
#server is assumed below because there is no K3S_URL
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend none --token 12345" sh -s -
curl -sfL https://get.k3s.io | sh -s - --flannel-backend none --token 12345
```

### Configuration with binary

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.

```
curl -Lo /usr/local/bin/k3s https://github.com/k3s-io/k3s/releases/download/v1.26.5+k3s1/k3s; chmod a+x /usr/local/bin/k3s
```

You can pass configuration by setting K3S_ environment variables:

```
k3s server --write-kubeconfig-mode=644
```

Or command flags:

```
k3s server --write-kubeconfig-mode=644
```

### Configuration File

In addition to configuring K3s with environment variables and CLI arguments, K3s can also use a config file.

By default, values present in a YAML file located at /etc/rancher/k3s/config.yaml will be used on install.

```
write-kubeconfig-mode: "0644"
tls-san:
- "foo.local"
node-label:
- "foo=bar"
- "something=amazing"
cluster-init: true
```

This is equivalent to the following CLI arguments:

```
k3s server \
--write-kubeconfig-mode "0644" \
--tls-san "foo.local" \
--node-label "foo=bar" \
--node-label "something=amazing" \
--cluster-init

```

### Advanced Options / Configuration

There are some advance ways to run and manage K3s.

You can access them [here](https://docs.k3s.io/advanced)

<style>
svg g .nodes #flowchart-couchInner2-4 .label div {
padding: 40px 0 40px 0;
}
svg g .nodes #flowchart-couchInner4-8 .label div,
svg g .nodes #flowchart-couchInner5-9 .label div,
svg g .nodes #flowchart-couchInner6-10 .label div
{
padding: 15px 0 15px 0;
}
.mermaid {
justify-content: center;
align-items: center;
display: flex;
}
</style>
37 changes: 35 additions & 2 deletions content/en/hosting/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ relatedContent: >
hosting/3.x/self-hosting
hosting/3.x/ec2-setup-guide
---

{{% pageinfo %}}
For production CHT deployments, Linux is recommended, with [Ubuntu](https://ubuntu.com/server) the most commonly used. For App Developer Hosting, Linux or macOS may be used. Windows can be used for either, but without recommendation.
{{% /pageinfo %}}
Expand Down Expand Up @@ -39,7 +38,7 @@ This leverages Docker and requires:

### Kubernetes

This guide refers to "Kubernetes", but Medic recommends a lightweight orchestrator called [K3s](https://docs.k3s.io/) for bare-metal hosts. The requirements below refer to K3s deployments but can be translated to other Kubernetes hosting. For example, for cloud hosting, we recommend Amazon [Elastic Kubernetes Service](https://aws.amazon.com/eks/) (EKS) and we've also assisted in a [large K3s deployment based on VMWare]({{< relref "4.x/production/kubernetes/self-hosting-k3s-multinode" >}}).
This guide refers to "Kubernetes", but Medic recommends a lightweight orchestrator called [K3s](https://docs.k3s.io/) for bare-metal hosts. The requirements below refer to K3s deployments but can be translated to other Kubernetes hosting. For example, for cloud hosting, we recommend Amazon [Elastic Kubernetes Service](https://aws.amazon.com/eks/) (EKS) and we've also assisted in a [large K3s deployment based on VMWare]({{< relref "4.x/production/kubernetes/self-hosting-k3s-multinode" >}}).

Be sure to see the `cht-deploy` [script](https://github.com/medic/cht-core/tree/master/scripts/deploy) that leverage the `helm` [application](https://helm.sh/docs/intro/install/).

Expand All @@ -54,5 +53,39 @@ Be sure to see the `cht-deploy` [script](https://github.com/medic/cht-core/tree/

_\* During some upgrades, up to 3x current space used by CouchDB can be needed_

## K3s

K3s is lightweight, but requires some minimum requirements to run.
Whether you're installing K3s to run a native linux service or a container, each node should meet a minimum requirements.

### **Architecture**

* x86_64
* armhf
* arm64/aarch64
* s390x

### **Operating Systems**

* K3s is expected to work on most modern Linux systems

### **Hardware requirements**

| Spec | Minimum | Recommended |
| ---- | ------- | ----------- |
| CPU | 1 Core | 2 Cores |
| RAM | 512 MB | 1 GB |

##### Disks

K3s performance depends on the performance of the database. To ensure optimal speed, we recommend using an SSD when possible.
Disk performance will vary on ARM devices utilizing an SD card or eMMC

### **Networking**

The K3s server needs port 6443 to be accessible by all nodes.
The nodes need to be able to reach other nodes over UDP port 8472 when using the Flannel VXLAN backend, or over UDP port 51820 (and 51821 if IPv6 is used) when using the Flannel WireGuard backend.

## Required skills

In addition to the hosting requirements, system administrators should have a basic understanding of command line interface, Kubernetes, docker, container orchestration, deployment, databases (CouchDB, Postgres), networking components (TLS, IP addresses, DNS).
Loading