Skip to main content
Version: Next

Kubernetes

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 (required for running kind clusters).
  • Kind (Kubernetes in Docker).
  • Kubectl (Kubernetes command-line tool).

Additionally, ensure that Kubernetes tools are enabled in your environment by setting the following variable in your .env file:

# 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:

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:

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:

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:

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​

kubectl get nodes

Expected output:

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​

kubectl get deployment -n kube-system metrics-server

Expected output:

NAME             READY   UP-TO-DATE   AVAILABLE   AGE
metrics-server 1/1 1 1 Xs

Get Node Resource Metrics​

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.