If you have already tried managed Kubernetes clusters, you will likely have come across different providers, their platforms and clients. Every provider and platform has their own way of getting things done, of configuring resources, and using those. This can be highly confusing.

At Civo we want to provide you with the fastest path to success. After all, it would not be of much use to start a cluster in just a few minutes like you can do on Civo, if you struggle in the process.

This blog post will provide you with 3 different ways on how you can start a Civo kubernetes cluster.

Kubernetes Cluster

Prerequisites

It’s best if you have the following installed, although you will not need those for the first option we show you.

You will, of course, need an account on Civo to follow along with this guide.

Launching a Cluster through the Web User Interface

We all interact with resources differently, some prefer to copy paste commands into their terminal, others like to click buttons in a pretty UI. Both paths will equally lead you to success.

To launch a cluster through the Civo UI follow these steps:

  1. Sign up to Civo if you haven't already. Note that, at the time of writing, if you are signing up for your first time, you can claim $250 of free credit by adding your credit card details to your account.

  2. Once you log in, you will be on the Dashboard overview. Navigate to the Kubernetes tab on the left side bar. You should see something similar to this screenshot:

Civo Dashboard

  1. Select Launch my first cluster. The options that are presented to me are as follows:

Launch Civo Kubernetes Cluster

Note that you can access additional options once you provide your credit card information.

  1. Let’s fill out the information for our cluster.
  2. Provide any name for your cluster that you would like. It could be something like “demo-cluster”, “staging” for an environment cluster, or just your name “anais-cluster”.
  3. The number of instances refer to the number of nodes that you want to have inside your cluster. We suggest you use three nodes as default and scale the number of nodes as you need to.
  4. We will use the Default Network
  5. In our case, we will create a Medium cluster size. Again, this depends on your resource needs.

Node Pool Size!

  • 5. Lastly, we can select the applications that we want to have pre-installed from the Civo Marketplace. Every cluster comes with one External IP automatically, which is by default allocated to Traefik. In case you want to use it for something else in your set-up you would have to remove Traefik as the default ingress controller to be installed.
  1. Click on “Create Cluster” to create your Civo Kubernetes Cluster. You will then see a bar at the top left that indicates the estimated time it will take for you to create the cluster.

Building a cluster

Creating a Cluster from the Civo CLI

This option is for everyone who prefers to copy-paste CLI commands. To follow these steps, you will need a Civo Account, kubectl and the Civo CLI installed.

Ensure everything is installed correctly

kubectl --version

civo --version

Civo CLI

First, we need to add an API key to connect to your account. You can find the API Key in the Civo UI. Go to Account > Settings > Security and you will find your API Key

Civo API Key Dashboard

Add your API Key to the Civo CLI:

civo apikey save <name your API Key> <API key>

Ensure that the CLI uses this API Key:

civo apikey current <name of your API Key>

List all your API keys and see the current one in use:

civo apikey ls

Display the current API Key:

civo apikey show

.4. Now that we have access to our Civo account through the Civo CLI, we can go ahead and create a new cluster

civo kubernetes create example-cluster --size "g3.k3s.medium" --nodes 3 --wait --save --merge --region NYC1

You can find all the options for the create command by running:

civo kubernetes create --help

The benefit of using the CLI is that you will be automatically connected to the kubeconfig if you include the option

--merge --save --wait

After the cluster has finished creating, you should be able to check your nodes through

kubectl get nodes

Creating a Civo Kubernetes cluster through Terraform

This option is for those who want to go one step further and manage their resources declaratively. In this step we are going to show you how you can create a Civo Kubernetes Cluster with Terraform.

If you would like to access further information on using the Civo Terraform provider, please refer to the full guide and to the repository.

Before getting started, please make sure you have Terraform and kubectl installed.

To use the Civo Terraform provider, we have to do the following:

  • Install the Civo Terraform Provider
  • Create a cluster resource

Install the Civo Terraform Provider

Create a new directory in which you want to create your Terraform Kubernetes Cluster resources. We are going to add a provider.tf file that is going to create our Provider resources. Paste into the provider.tf file the following configuration:

provider "civo" {
  token = "<your API token>"
}

terraform {
  required_version = ">= 0.13.0"
  required_providers {
    civo = {
      source = "civo/civo"
    }
  }
}

provider "kubernetes" {
  host     = civo_kubernetes_cluster.cluster.api_endpoint
  username = yamldecode(civo_kubernetes_cluster.cluster.kubeconfig).users[0].user.username
  password = yamldecode(civo_kubernetes_cluster.cluster.kubeconfig).users[0].user.password
  cluster_ca_certificate = base64decode(
    yamldecode(civo_kubernetes_cluster.cluster.kubeconfig).clusters[0].cluster.certificate-authority-data
  )
}

Please make sure to replace the API token lister under provider "civo". You can find the current API token that you are using through civo apikey show.

Now we can run the following command to initialise our Terraform directory:

terraform init

You should now see a .terraform/ directory in your current directory. This directory contains the Civo Provider details.

Create Civo Kubernetes Cluster resource

Next, we need to create a Civo Kubernetes Cluster definition in Terraform.

resource "civo_kubernetes_cluster" "cluster" {
  name              = "<name you want to give your cluster>"
  applications      = ""
  num_target_nodes  = 3
  target_nodes_size = element(data.civo_instances_size.small.sizes, 0).name
  region            = "NYC1"
}

data "civo_kubernetes_cluster" "cluster" {
  name = civo_kubernetes_cluster.cluster.name
}

data "civo_instances_size" "small" {
    filter {
        key = "type"
        values = ["kubernetes"]
    }
}

You can find further information on the data that can be specified by running the following commands:

terraform refresh
terraform console
data.civo_instances_size.small

After specifying the fields for your Kubernetes cluster please run terraform plan to ensure it can be created correctly. This should not throw any errors. However, if you receive any errors, you can now make sure to fix those.

Lastly, we can create our cluster by running terraform apply. You should see an output similar to the following:

Terraform Apply Completed

You did it!

You just created your first K3s Civo Kubernetes Cluster. It works in a similar way to any other Kubernetes cluster. For inspiration, guides and tutorials have a look at the Civo Learn Portal.