Search⌘ K
AI Features

Setting up the Kubernetes Cluster

Explore the steps to set up a managed Kubernetes cluster on DigitalOcean. Learn to generate access tokens, configure doctl, create a single-node cluster, and verify connectivity. This lesson prepares you to build serverless apps within a Kubernetes environment.

We'll cover the following...

We’ve based this course on using a managed Kubernetes cluster from DigitalOcean, so you’ll need one in order to follow along. If you don’t have an account at DigitalOcean, you can create one by visiting DigitalOcean directly or using this referral link.  At the time of writing this course, DigitalOcean gives you a $100 credit to try out different features on it.

We'll create a cluster using doctl, the official command-line interface for the DigitalOcean API.

Create the DigitalOcean Kubernetes cluster

After creating an account on DigitalOcean, we need to generate an access token to use the API. To generate the personal access token, follow the steps provided here.

The figure below shows a sample token. The actual token is the long string of numbers and letters under the “Name” field. It will be prefixed with dop_v1_ to distinguish it from other similar tokens.

Now that we’ve registered an account and have the access token, we’re ready to create the cluster. Before clicking the “Run” button, please click “edit” and set the API value of ACCESS_TOKEN API. This will help us automatically set up our environment in the upcoming lessons so that we don’t have to give access tokens again. Now, click the “Run” button for the widget shown below. Once it’s connected to the terminal, enter the first command given in the clusterSetup.sh file to configure doctl.

Note: In order to run all the commands written in a .sh file, just type ./file-name.sh in the terminal.

For instance, typing ./clusterSetup.sh will execute the commands for all the steps mentioned in this lesson.

#1. Configure doctl
doctl auth init --access-token {{ACCESS_TOKEN}}

#2. Create a cluster with the name "serverless-app-platform"
doctl kubernetes cluster create serverless-app-platform --region fra1 --size s-2vcpu-4gb --count 1

#3. See the nodes
kubectl get nodes
Setting up the Kubernetes cluster

Once doctl is configured, use the second command given in the clusterSetup.sh file to create our cluster on DigitalOcean.

Wait a few minutes for the cluster to be ready. Once done, we should have a single-node cluster with the name serverless-app-platform in Frankfurt. The node size is a machine with two vCPUs and 4GB RAM. Also, the command we just executed will set the current Kubectl context to that of the new cluster.

We can modify the values passed to the doctl kubernetes cluster create command. The --region flag indicates the cluster region. Run the command doctl kubernetes options regions to see possible values that can be used. The machine size when creating nodes is specified using the --size flag. Run the command doctl kubernetes options sizes for a list of possible values. The --count flag specifies the number of nodes to create. We created a single-node cluster with two vCPUs and 4GB RAM for prototyping purposes.

To verify that we can connect to the cluster, we can use kubectl. Run the third command given in the clusterSetup.sh file. We should see one node in the list, and the STATUS should be Ready, as shown below:

NAME                                          STATUS    ROLES    AGE    VERSION
serverless-app-platform-default-pool-xxxxx    Ready     <none>   104s    v1.23.9

Next, we need to use the following command to reuse the existing cluster for the rest of the course. In the command, serverless-app-platform represents the cluster name, and the command sets the current context of our doctl to the serverless-app-platform cluster.

doctl kubernetes cluster kubeconfig save serverless-app-platform