k8s

Setting Up a Kubernetes Cluster with k3s on Bare Metal Server

"Configure kubernetes"

Posted by Backend Byte on May 18, 2024

Introduction

This article provides a step-by-step guide for setting up a Kubernetes cluster using k3s on a bare metal server. k3s is a lightweight Kubernetes distribution designed for resource-constrained environments, making it ideal for bare metal setups.

Installation Steps

1. Install k3s

Run the following command to install k3s on your bare metal server:

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

This command fetches the k3s installation script from the internet and executes it on your server.

2. Verify Installation

After the installation completes, a kubeconfig file will be generated at /etc/rancher/k3s/k3s.yaml, and the kubectl command-line tool provided by k3s will automatically configure itself to use this file.

To verify that the installation was successful and that the server is functioning as a Kubernetes master node, run the following command:

sudo kubectl get nodes

If the command returns a list of nodes including the master node, the installation was successful.

Note:

  • If you encounter permission issues with the kubectl command, try running it as a superuser using sudo -i or sudo su.

3. Access Tokens

During the installation process, k3s generates access tokens that can be used to join additional nodes to the cluster. These tokens are stored on the master node.

To obtain the access tokens, run the following command:

cat /var/lib/rancher/k3s/server/node-token

Make note of the token value as it will be required when joining worker nodes to the cluster.

  1. Register worker node
curl -sfL https://get.k3s.io | K3S_URL=https://<server_ip>:6443 K3S_TOKEN=<node_token> sh -

Conclusion

You have successfully installed k3s on your bare metal server and configured it as a Kubernetes master node. You can now proceed to add worker nodes to your cluster using the generated access tokens.

For more information on managing and configuring your k3s cluster, refer to the official k3s documentation:

https://docs.k3s.io/quick-start

Happy Kubernetes clustering!