Files
homarr/apps/docs/docs/advanced/development/kubernetes.mdx
T

135 lines
3.8 KiB
Plaintext

---
title: Kubernetes
tags:
- Developer
- Technical documentation
- Code
- Programming
sidebar_position: 1
---
This guide provides step-by-step instructions for setting up a Kubernetes cluster using kind, configuring multiple nodes, and installing the Metrics Server.
## Prerequisites
Ensure you have the following installed:
- [Docker](https://docs.docker.com/get-started/get-docker/) (required for running `kind` clusters).
- [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/) (Kubernetes in Docker).
- [Kubectl](https://kubernetes.io/docs/tasks/tools/) (Kubernetes command-line tool).
Additionally, ensure that Kubernetes tools are enabled in your environment by setting the following variable in your `.env` file:
```bash
# Enable Kubernetes tool
ENABLE_KUBERNETES=true
```
### 1. Creating a Kubernetes Cluster with Multiple Nodes
We will create a Kubernetes cluster using `kind` with one control plane node and two worker nodes.
#### Define the Cluster Configuration
Create a configuration file named `kind-config.yaml` with the following content:
```bash
cat > kind-config.yaml <<EOF
# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
kubeReserved:
cpu: "250m"
memory: "256Mi"
systemReserved:
cpu: "500m"
memory: "512Mi"
evictionHard:
memory.available: "200Mi"
- role: worker
- role: worker
EOF
```
#### Create the Cluster
Run the following command to create the Kubernetes cluster:
```bash
kind create cluster --name k8s-playground --config kind-config.yaml
```
This will provision a cluster named `k8s-playground` with the specified node configuration.
### 2. Installing the Metrics Server
The Metrics Server is required for gathering resource utilization metrics like CPU and memory usage. It is essential for features such as Horizontal Pod Autoscaling.
#### Deploy the Metrics Server
Run the following command to install the Metrics Server:
```bash
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.7.2/components.yaml
```
#### Disable TLS Verification (For Local Development)
In local environments, Kubernetes nodes might not have valid certificates. To disable TLS verification, patch the deployment:
```bash
kubectl patch -n kube-system deployment metrics-server --type=json \
-p '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]'
```
This allows the Metrics Server to communicate with kubelets that use self-signed certificates.
### 3. Verifying the Setup
After completing the setup, verify that the cluster is running correctly:
#### Check the Cluster Nodes
```bash
kubectl get nodes
```
Expected output:
```bash
NAME STATUS ROLES AGE VERSION
k8s-playground-control-plane Ready control-plane Xs vX.Y.Z
k8s-playground-worker Ready worker Xs vX.Y.Z
k8s-playground-worker2 Ready worker Xs vX.Y.Z
```
#### Check Metrics Server Status
```bash
kubectl get deployment -n kube-system metrics-server
```
Expected output:
```bash
NAME READY UP-TO-DATE AVAILABLE AGE
metrics-server 1/1 1 1 Xs
```
#### Get Node Resource Metrics
```bash
kubectl top nodes
```
This command should return CPU and memory usage statistics for each node.
## Conclusion
You have successfully set up a multi-node Kubernetes cluster using kind and installed the Metrics Server for monitoring resource usage. This setup is useful for local development and testing Kubernetes workloads before deploying them to a production environment.