1. Answers
  2. Setting up a DigitalOcean Kubernetes Cluster

How do I set up a DigitalOcean Kubernetes cluster?

To set up a Kubernetes cluster in DigitalOcean, you can define a configuration that automates the provisioning of the required resources. This setup involves creating a DigitalOcean Kubernetes cluster, specifying its version, region, and node pool details. You will also create outputs to capture essential cluster information such as the Cluster name and the kube_config that you can use to interact with the cluster.

Below is an example of how to achieve this using Infrastructure as Code:

import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const example = new digitalocean.KubernetesCluster("example", {
    name: "example-cluster",
    region: digitalocean.Region.NYC1,
    version: "1.21.5-do.0",
    nodePool: {
        name: "worker-pool",
        size: "s-2vcpu-4gb",
        nodeCount: 3,
    },
});
export const clusterId = example.id;
export const kubeConfig = example.kubeConfigs.apply(kubeConfigs => kubeConfigs[0].rawConfig);

Explanation

DigitalOcean Provider:

  • The provider block specifies the DigitalOcean provider necessary for managing resources on DigitalOcean. The token required should be stored securely.

Kubernetes Cluster Resource:

  • The digitalocean_kubernetes_cluster resource creates a new Kubernetes cluster.
  • name sets the cluster name.
  • region specifies the data center where the cluster will be created.
  • version denotes the version of Kubernetes.
  • node_pool is defined to set up the worker nodes, specifying the name, size, and number of nodes in the pool.

Outputs:

  • cluster_id exports the ID of the Kubernetes cluster.
  • kube_config exports the kubeconfig file, which can be used to configure kubectl to connect to your new cluster.

This setup allows you to provision a fully functional Kubernetes cluster on DigitalOcean, configured and managed through code.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up