Creating a K8s Cluster with Zarf
In this tutorial, we will demonstrate how to use Zarf on a fresh Linux machine to deploy a k3s cluster through Zarf's k3s
component.
System Requirements
root
access on a Linux machine
The 'k3s' component requires root access (not just sudo
!) when deploying as it will modify your host machine to install the cluster.
Prerequisites
Before beginning this tutorial you will need the following:
- The Zarf repository cloned: (
git clone
Instructions) - Zarf binary installed on your $PATH: (Installing Zarf)
- An init-package built/downloaded: (init-package Build Instructions) or (Download Location)
Creating the Cluster
- Run the
zarf init
command asroot
.
# zarf init
- Confirm Package Deployment:
- When prompted to deploy the package select
y
for Yes, then hit theenter
key.
- Confirm k3s Component Deployment:
- When prompted to deploy the k3s component select
y
for Yes, then hit theenter
key.
You can automatically accept the k3s component and confirm the package using the --components
and --confirm
flags.
$ zarf init --components="k3s" --confirm
Validating the Deployment
After the zarf init
command is done running, you should see a k3s cluster running and a few zarf
pods in the Kubernetes cluster.
# zarf tools monitor
You can press 0
if you want to see all namespaces and CTRL-C to exit
Accessing the Cluster as a Normal User
By default, the k3s component will only automatically provide cluster access to the root user. To access the cluster as another user, you can run the following to setup the ~/.kube/config
file:
# cp /root/.kube/config /home/otheruser/.kube
# chown otheruser /home/otheruser/.kube/config
# chgrp otheruser /home/otheruser/.kube/config
Cleaning Up
The zarf destroy
command will remove all of the resources, including the k3s cluster, that was created by the initialization command.
zarf destroy --confirm