Skip to content
This repository was archived by the owner on Apr 17, 2024. It is now read-only.

Commit 5d5eba1

Browse files
authored
Merge pull request #2 from koor-tech/feature/gen-176
docs: add documentation for setup kubernetes cluster
2 parents ea6f560 + ae0368c commit 5d5eba1

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,19 @@
33
For managing the infrastructure to run our demo system
44

55
A new best practice for managing K8s infrastructure is to store configuration in Git and use PRs to make sure changes get reviewed. Seems like a great idea.
6+
7+
## Setting up KSD
8+
9+
KSD can be effortlessly deployed in various environments, including bare metal or the cloud.
10+
In this example, we will demonstrate an automated environment configuration to showcase how easily you can prepare for testing KSD in your preferred setup.
11+
12+
13+
### 1. Deploy your Kubernetes Cluster in Hetzner Cloud
14+
15+
Read how you can [install your Kubernetes Cluster to use KSD](kubernetes-cluster-demo/setup-demo.md)
16+
17+
18+
19+
20+
21+
24.5 KB
Loading
1.08 MB
Loading
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
## Setup a Kubernetes Cluster for KSD using Hetzner Cloud
2+
3+
This guide is to be ready and test KSD easily.
4+
5+
### IMPORTANT:
6+
7+
In order to be able to follow all the steps, you would need a Hetzner Api token, to get this you will need:
8+
- Sign in into the Hetzner Cloud Console
9+
- choose a Project
10+
- go to Security → API Tokens
11+
- generate a new token.
12+
13+
Once you have your token, you must export your token in order to use it during the process
14+
```console
15+
$ export HCLOUD_TOKEN=GlPz.....
16+
```
17+
18+
19+
> If you have troubles, please visit the Hetzner Cloud Documents [https://docs.hetzner.cloud/](https://docs.hetzner.cloud/)
20+
21+
## Requirements
22+
23+
- Kubeone
24+
- You can install it by using `curl -sfL https://get.kubeone.io | sh`
25+
- Terraform v1.5.2
26+
- A new ssh key only for this purpose (how to generate a new ssh-key)
27+
- Kubectl (how to install kubectl)
28+
- Api Token Hetzner Cloud
29+
30+
31+
## Architecture
32+
33+
![architecture.png](architecture.png)
34+
35+
## Hands On
36+
37+
It's time to prepare your Kubernetes cluster for KSD usage.
38+
39+
#### 1. Clone this repository
40+
41+
```console
42+
git clone [email protected]:koor-tech/demo-gitops.git
43+
```
44+
45+
#### 2. Navigate to kubernetes-cluster-demo
46+
47+
```console
48+
$ cd kubernetes-cluster-demo/terraform/
49+
```
50+
51+
#### 3. Initialize the terraform configuration
52+
53+
```console
54+
$ terraform init
55+
56+
Initializing the backend...
57+
58+
Initializing provider plugins...
59+
- Finding hetznercloud/hcloud versions matching "~> 1.31.0"...
60+
- Installing hetznercloud/hcloud v1.31.1...
61+
- Installed hetznercloud/hcloud v1.31.1 (signed by a HashiCorp partner, key ID 5219EACB3A77198B)
62+
63+
Partner and community providers are signed by their developers.
64+
If you'd like to know more about provider signing, you can read about it here:
65+
https://www.terraform.io/docs/cli/plugins/signing.html
66+
67+
Terraform has created a lock file .terraform.lock.hcl to record the provider
68+
selections it made above. Include this file in your version control repository
69+
so that Terraform can guarantee to make the same selections by default when
70+
you run "terraform init" in the future.
71+
72+
Terraform has been successfully initialized!
73+
74+
You may now begin working with Terraform. Try running "terraform plan" to see
75+
any changes that are required for your infrastructure. All Terraform commands
76+
should now work.
77+
78+
If you ever set or change modules or backend configuration for Terraform,
79+
rerun this command to reinitialize your working directory. If you forget, other
80+
commands will detect it and remind you to do so if necessary.
81+
```
82+
83+
#### 4. Setup your cluster
84+
85+
Inside the terraform folder you could find a file called `terraform.tfvars.example` use that file to set up your cluster as you need
86+
```console
87+
$ cp terraform.tfvars.example terraform.tfvars
88+
```
89+
90+
KSD is versatile and can run on various clusters, yet in a production environment,
91+
the following are the essential minimum requirements:
92+
93+
- 3 Nodes in control plane
94+
- 4 CPU
95+
- 8 GB RAM
96+
- 3 Nodes on data/worker nodes
97+
- 8 CPU
98+
- 16 GB RAM
99+
- Calico as CNI (Other CNI plugins work pretty well)
100+
101+
#### 4. Validate your changes
102+
103+
Run `terraform plan` to examine what changes will be applied in your infrastructure
104+
```console
105+
$ terraform plan
106+
hcloud_placement_group.control_plane: Refreshing state... [id=185187]
107+
hcloud_load_balancer.load_balancer[0]: Refreshing state... [id=1361514]
108+
hcloud_network.net: Refreshing state... [id=3137203]
109+
hcloud_ssh_key.kubeone: Refreshing state... [id=13174070]
110+
hcloud_firewall.cluster: Refreshing state... [id=975915]
111+
hcloud_server.control_plane[0]: Refreshing state... [id=35048829]
112+
hcloud_server.control_plane[2]: Refreshing state... [id=35048828]
113+
hcloud_server.control_plane[1]: Refreshing state... [id=35048830]
114+
hcloud_network_subnet.kubeone: Refreshing state... [id=3137203-192.168.0.0/16]
115+
hcloud_load_balancer_service.load_balancer_service[0]: Refreshing state... [id=1361514__6443]
116+
hcloud_load_balancer_network.load_balancer[0]: Refreshing state... [id=1361514-3137203]
117+
hcloud_server_network.control_plane[0]: Refreshing state... [id=35048829-3137203]
118+
hcloud_server_network.control_plane[2]: Refreshing state... [id=35048828-3137203]
119+
hcloud_server_network.control_plane[1]: Refreshing state... [id=35048830-3137203]
120+
.....
121+
```
122+
123+
#### 4. Apply your changes
124+
125+
These changes only will create your infrastructure and Kubernetes will be installed later
126+
```console
127+
$ terraform apply
128+
129+
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
130+
+ create
131+
132+
Terraform planned the following actions, but then encountered a problem:
133+
134+
# hcloud_firewall.cluster will be created
135+
+ resource "hcloud_firewall" "cluster" {
136+
+ id = (known after apply)
137+
+ labels = {
138+
+ "kubeone_cluster_name" = "koor-demo"
139+
}
140+
+ name = "koor-demo-fw"
141+
142+
+ apply_to {
143+
+ label_selector = "kubeone_cluster_name=koor-demo"
144+
+ server = (known after apply)
145+
}
146+
147+
+ rule {
148+
+ description = "allow ICMP"
149+
+ destination_ips = []
150+
+ direction = "in"
151+
+ protocol = "icmp"
152+
+ source_ips = [
153+
....
154+
```
155+
156+
#### 5. Save your infrastructure
157+
158+
You need to save your terraform state into a tf.json file that will be used later for setup your Kubernetes Clusters
159+
```console
160+
$ terraform output -json > tf.json
161+
```
162+
163+
#### 6. Deploy your Cluster
164+
165+
You already have a `kubeone.yaml` file with the required configuration, but you can update it as you need, and just you need to run:
166+
```console
167+
$ kubeone apply -m kubeone.yaml -t tf.json
168+
```
169+
170+
#### 7. Add your volumes
171+
172+
For this step, you will need to access to your hetzner cloud account [https://accounts.hetzner.com/login](https://accounts.hetzner.com/login)
173+
174+
1. Access to your hetzner cloud account
175+
2. Open your project
176+
3. Go to volumes and add a new volume of your desire size
177+
4. Set the volume name
178+
5. Choose the server
179+
- **important: Choose one server that contains in its name "pool" to use nodes from the data plane**
180+
- Caution: Avoid selecting control plane nodes for KSD, as it relies on deploying pods tied to the volumes. Control plane nodes are unable to host such pods due to [taints and tolerations](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/).
181+
6. Select in *Choose mount options*, **manually** to be able to manage completely by KSD
182+
7. Finally, click on create and buy
183+
8. We recommended setting at least one volume per node to be able to use all the KSD features
184+
185+
See the image to check how to do that
186+
187+
![how to create a volume](how-to-create-volume.gif)
188+
189+
With the steps above, you will have readied your minimum production Kubernetes Cluster to be used to deploy KSD
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: kubeone.k8c.io/v1beta2
2+
kind: KubeOneCluster
3+
versions:
4+
kubernetes: '1.25.6'
5+
cloudProvider:
6+
hetzner: {}
7+
external: true
8+
9+
clusterNetwork:
10+
cni:
11+
external: {}
12+
13+
addons:
14+
enable: true
15+
addons:
16+
- name: calico-vxlan
17+
params:
18+
MTU: "0" # auto-detect MTU

0 commit comments

Comments
 (0)