How to Configure DigitalOcean Kubernetes Infrastructure

How to Configure DigitalOcean Kubernetes Infrastructure

A complete guide to deploying your application on DigitalOcean Kubernetes

Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

Containerized applications are applications that comes bundled with everything required to setup, run and deploy them. In context, they have already been setup completely and just requires you to run them. Some examples of containerization technologies are docker, rkt, runC etc.

We are not focusing on how containers work and how to use them because i assume you already have knowledge of containerization technology and how to use them to run your applications. We will be focusing on how to setup and deploy containerized technology on the cloud.

We have several cloud computing companies like AWS, Google Cloud, Azure, DigitalOcean etc that offer kubernetes infrastructure as a service but we will be focusing on deploying our applications on DigitalOcean Kubernetes Service (DOKS).


We will substitute the following words with their defined shortcuts.

  • DigitalOcean - DO

  • DigitalOcean Kubernetes Service - DOKS

  • Kubernetes - K8s

  • Virtual Private Cloud - VPC


To effectively follow through in this guide, you will be required to have K8s setup locally on your system, a DO account and dockerized application.

Initial Setup

We will be setting up our kubernetes cluster and all the necessary infrastructure needed to make it work effectively and run our applications.

Kubernetes Cluster Setup

Login into your DO account and Select the manage drop-down from the side menu. Under the manage drop-down, select Kubernetes menu item to open the K8s clusters page.

Click the Create drop-down on the navigation bar of the page and select the Kubernetes item on the list.

Create a cluster page

Screenshot 2021-06-04 at 18-37-52 Control Panel - DigitalOcean.png

Select a K8s version

Always use the latest version because it is up to update

Choose a data center region

Choose a data center closer to your target users to have improved speed and access to data

Select a VPC network

Resources within a VPC communicate securely over their private IP addresses, making communication faster.

Choose cluster capacity

Choose the node pool name, the memory and CPU size and the total number of nodes to deploy (this can be updated anytime).

Add Tags

Add special tag names used to identify your resources

Choose a name

Choose a name to identify your cluster

Select Project

Select the DO project to create the cluster

After creating the K8s cluster, wait for some minutes for the cluster to be completely initialized.

Connect cluster to local K8s setup

Since we already have K8s setup locally on your system, let us connect to our DOKS cluster from our system so we can complete our cluster setup to run our applications.

Install the DO doctl, the official command-line interface (CLI) for the DO API. This can also be used this to manage your DO resources.

There are two methods to connect to a DOKS cluster, we will be going through them one after the other.

Manual Connection

Download the the config file on the cluster page using the Download Config File button in the Access Cluster Config File section.

Screenshot 2021-06-04 at 18-42-12 Cluster - DigitalOcean.png

The file is named in the format (clustername)-kubeconfig.yaml. Move this file to your ~/.kube directory and run the command below to generate a token and connect to cluster

kubectl --kubeconfig=~/.kube/<clustername>-kubeconfig.yaml get nodes

Using DO doctl

From your command line, run the command below to connect to DO using the installed doctl, generate a token and connect to all the clusters on DOKS.

doctl kubernetes cluster kubeconfig save your_cluster_name_here

It is recommended to use the doctl method as it saves you time and you have a very low possibility to make an error.

Set Kubernetes kubectl context to DOKS cluster

During the connection, the DOKS cluster is imported in you K8s kubectl context directory. Check the context list to confirm your cluster is the using the command below

kubectl config get-contexts

Set the current context to your DOKS cluster

kubectl config use-context your_cluster_context_name

Setup Our Cluster to able to expose a web server

Let us configure our kubernetes to be able to expose any application to the public web. We can do this using the Nginx ingress controller.

How to Install

From the DO marketplace, search for Nginx ingress controller, on the app page, click the "Install App" button. you will be redirected to the cluster page

Screenshot 2021-06-04 at 18-37-02 NGINX Ingress Controller Hosting DigitalOcean Marketplace 1-Click App.png

When the cluster page opens, a modal will appear for you to select the cluster to install the app. Select the DOKS cluster and click Install

Screenshot 2021-06-04 at 18-37-29 Control Panel - DigitalOcean.png

After the installation is complete, connect to your DOKS cluster from your local kubectl connection and run the command below to verify that nginx ingress is running

kubectl get pods --all-namespaces -l

Also run the command below to get the external ip of the newly created loadbalancer

kubectl get svc -n ingress-nginx

Visit the DO Networking page from the side menu and select the Load Balancers tab, you should find a newly created Load Balancer for your DOKS cluster.

Container Registry

We have fully setup our K8s cluster to run and manager our containers but we need to access these containers and K8s has to pull these containers from a location, comes in the Container Registry.

In simple terms, a container registry is just a store for our containerized application images. There are so many container registries but we will be focusing on the DO container registry in order to have a seamless experience.

DO Container Registry Setup

From the side menu, select Container Registry from the list. Enter the registry name and select the plan (this can be changed anytime).

Screenshot 2021-06-04 at 19-09-39 Create private Container Registry - DigitalOcean.png

Note: Only one container registry can be created per project on DO

Now we have successfully created our container registry, let's connect our K8s cluster to the registry to allow the cluster pull container images directly from it.

Connect K8s cluster to our newly created registry

Open the container registry page and click the Settings tab.

Screenshot 2021-06-04 at 19-15-51 Container Registry settings - DigitalOcean.png

Under the DigitalOcean Kubernetes Integration, select your K8s cluster and click save.

This action will setup the registry secret on your K8s cluster allowing it to pull images stored on the registry.

Now we have fully configured DOKS kubernetes cluster to deploy and run our application images and also a container registry to hold our application images on DO. Next we will be deploying a test application to the registry and also run the application on our K8s cluster.