Categories
Automation CI/CD DevOps

How to Create Kubernetes cluster on Linode using CLI

Today, I’ll show how to create Kubernetes cluster on Linode using CLI. It might be useful, for instance, for CI/CD, automation processes, etc…

If you later find this article useful take a look at the disclaimer for information on how to thank me.

What is Linode?

Linode is a cloud provider recently purchased by Akamai. With this purchase, Akamai became a competitor in the cloud providers market. Linode offers managed Kubernetes service of various competitive pricing and cluster sizing options. We saw already how easy it is to create Kubernetes Cluster on Linode using its cloud manager UI. The time has come to show how easy it is to create a Kubernetes cluster on Linode using CLI.

Motivation

As soon as you discover the charm of automation, its speed and ease of use, your search for doing stuff using CLI. The same is true for creating Kubernetes clusters on Linode. With the courteousness of Linode developers and its open source community, linode-cli was developed. While you can use it for managing all aspects of your Linode account using CLI, we’ll focus today on the creation of Kubernetes clusters. linode-cli will be your best friend in CI/CD pipelines and automation. For example, you might want to create an on-demand Kubernetes cluster for acceptance testing of your helm charts in the chart’s release pipeline. And of course, you can create a Kubernetes cluster for all the demos on rokpoto.com mentioning Kubernetes and Linode.

Create Kubernetes cluster on Linode using CLI Demo

Let’s now see a demo showing how to create a Kubernetes cluster on Linode using CLI.

Demo Prerequisites

You’ll need your own Linode account. Create one and get 100$ credit using this link.

You’ll also need python and pip for installing and running linode-cli as it’s basically a python package. In addition, install  kubectl on your local machine for interacting with Linode Kubernetes cluster.

Install linode-cli

Let’s install linode-cli using pip:

pip install linode-cli

Configure linode-cli to use Linode account

You have 2 options for configuring linode-cli to use your Linode account.

  1. Run linode-cli and type enter. You’ll see below output:
Welcome to the Linode CLI.  This will walk you through some initial setup.                                                            
                                                                                                                                      
The CLI will use its web-based authentication to log you in.  If you prefer to supply a Personal Access Token, use `linode-cli configure --token`.                                                                                                                          
                                                                                                                                      
Press enter to continue.  This will open a browser and proceed with authentication.

Type another enter and login to Linode if you are not logged in already. Follow the instructions in the command line for configuring the defaults for the CLI. You may also click enter to skip configuring defaults. The configuration is stored at ~/.config/linode-cli. Edit it or run linode-cli configure to set the defaults again anytime.

2. Alternatively, you may also generate and copy your Linode personal access token from your account and then run linode-cli configure --token to use it.

Create Kubernetes cluster on Linode

Let’s now create managed Kubernetes cluster on Linode:

linode-cli lke cluster-create   --label cluster12345   --region us-central   --k8s_version 1.25 --node_pools.type g6-standard-4 --node_pools.count 1 --format id --text --no-headers

It will return immediately with the id of the cluster, while the creation takes place in the background.

The command is self-explaining. I created the cluster of the specific version in a specific region. The cluster will run on a specified number of Linodes (VMs in Linode language) of the specific type.

You may use linode-cli linodes types command to find out the supported node types:

Whereas, linode-cli regions ls will show you Linode regions.

Use Kubernetes cluster on Linode

Kubernetes cluster creation on Linode usually lasts several minutes. After the cluster’s successful creation, let’s download its kubeconfig.

linode-cli lke kubeconfig-view [cluster_id] --text --no-headers | base64 -d > /tmp/test-config.yaml

Above command downloads kubeconfig in base64 encoding, decodes it and saves it to /tmp/test-config.yaml file.

You can merge this to your ~/.kube/config or use it directly in kubectl or helm commands.

Let’s install RabbitMQ using helm using the same commands we used when I showed Kubernetes StatefulSets Demo:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install --kubeconfig /tmp/test-config.yaml rabbitmq -n rabbitmq --create-namespace bitnami/rabbitmq --set service.type=LoadBalancer --wait --debug

Note the explicit --kubeconfig usage and --debug flag which shows the progress of the chart’s installation. In addition, --wait flag will wait till the successful chart’s installation within the default timeout of 5 minutes or declare its status as failed.

After chart’s installation completion, inspect the resources in rabbitmq namespace using kubectl.

kubectl --kubeconfig /tmp/test-config.yaml get all -n rabbitmq
NAME             READY   STATUS    RESTARTS   AGE
pod/rabbitmq-0   1/1     Running   0          15m

NAME                        TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)                                                         AGE
service/rabbitmq            LoadBalancer   10.128.191.88   45.79.243.151   5672:31506/TCP,4369:31335/TCP,25672:32544/TCP,15672:32242/TCP   15m
service/rabbitmq-headless   ClusterIP      None            <none>          4369/TCP,5672/TCP,25672/TCP,15672/TCP                           15m

NAME                        READY   AGE
statefulset.apps/rabbitmq   1/1     15m

Delete Linode Kubernetes cluster and clean up CSI volumes

To delete the cluster along with its resources (Linode) run linode-cli lke cluster-delete [cluster_id].

It’s important to note though that if the chart requested some storage using PVCs, CSI volumes were dynamically provisioned by Linode using its default storage class. Be aware that these volumes are not deleted after cluster deletion. You’ll have to delete them separately, e.g. using linode-cli 🙂 Use linode-cli volumes rm [volume_id] command to achieve that.

Summary

That’s it about the creation of a Kubernetes cluster on Linode using CLI. It’s cool that we used CLI only throughout the demo. As always, feel free to share.

If you found this article useful, take a look at the disclaimer for information on how to thank me.

Recommended Kubernetes courses on Pluralsight:

Sign up using this link to get exclusive discounts like 50% off your first month or 15% off an annual subscription)

Recommended Kubernetes books on Amazon.