Skip to content

Create and prepare a Kubernetes cluster with k0s#

Follow these steps to install and prepare a k0s kubernetes management cluster:

  1. Deploy a Kubernetes cluster

    The first step is to create the actual cluster itself. Again, the actual distribution used for the management cluster isn't important, as long as it's a CNCF-compliant distribution. That means you can use an existing EKS cluster, or whatever is your normal corporate standard.

    To make things simple this guide uses k0s, a small, convenient, and fully-functional distribution:

    curl --proto '=https' --tlsv1.2 -sSf https://get.k0s.sh | sudo sh
    sudo k0s install controller --enable-worker --no-taints
    sudo k0s start
    

    k0s includes its own preconfigured version of kubectl so make sure the cluster is running:

    sudo k0s kubectl get nodes
    

    After 2-3 minutes you should see a single control-plane node with a status of Ready, as in:

    NAME              STATUS   ROLES            AGE   VERSION
    ip-172-31-29-61   Ready    control-plane    46s   v1.31.2+k0s
    
  2. Install kubectl

    Everything you do in k0rdent is done by creating and manipulating Kubernetes objects, so you'll need to have kubectl installed. You can find the full install docs here, or just follow these instructions:

    sudo apt-get update
    sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
    curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
    sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg # allow unprivileged APT programs to read this keyring
    echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
    sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list   # helps tools such as command-not-found to work correctly
    sudo apt-get update
    sudo apt-get install -y kubectl
    
  3. Get the kubeconfig

    In order to access the management cluster you will, of course, need the kubeconfig. Again, if you're using another Kubernetes distribution follow those instructions to get the kubeconfig, but for k0s, the process involves simply copying the existing file and adding it to an environment variable so kubectl knows where to find it.

    sudo cp /var/lib/k0s/pki/admin.conf KUBECONFIG
    sudo chmod +r KUBECONFIG
    export KUBECONFIG=./KUBECONFIG
    

    Now you should be able to use the non-k0s kubectl to see the status of the cluster:

    kubectl get nodes
    

    Again, you should see the single k0s node, but by this time it should have had its role assigned, as in:

    NAME              STATUS   ROLES           AGE   VERSION
    ip-172-31-29-61   Ready    control-plane   25m   v1.31.2+k0s
    

    Now the cluster is ready for installation, which we'll do using Helm.

  4. Install Helm

    The easiest way to install k0rdent is through its Helm chart, so let's get Helm installed. You can find the full instructions here, or use these instructions:

    curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
    chmod 700 get_helm.sh
    ./get_helm.sh
    

    Helm will be installed into /usr/local/bin/helm.