This Terraform module provides a simple and flexible way to create and manage Kubernetes clusters on DigitalOcean (DOKS).
The terraform-do-doks module abstracts the complexity of creating a Kubernetes cluster on DigitalOcean, allowing you to define your infrastructure declaratively. It includes features such as:
- DOKS Cluster: Create a fully managed Kubernetes cluster
- Multiple Node Pools: Define multiple node groups with different configurations
- Autoscaling: Configure automatic node scaling
- Integrations: Enable container registry and routing
- Taints and Labels: Control which pods can run on which nodes
- Project Integration: Automatically assign resources to DigitalOcean projects
- Terraform >= 1.0
- DigitalOcean Provider >= 2.0
- DigitalOcean API token configured in your environment
- Configurable name, region, and Kubernetes version
- Custom VPC for the cluster
- Tags to organize your resources
- Default Pool: Included automatically
- Additional Pools: Define as many node groups as you need
- Autoscaling: Each additional pool has autoscaling enabled
- Taints and Labels: For advanced pod scheduling control
- Container Registry: Optional integration with DigitalOcean Container Registry
- Routing Agent: Ingress controller for DigitalOcean
- Cluster Autoscaler: Configurable for automatic node scaling
| Variable | Type | Description |
|---|---|---|
doks_name |
string | DOKS cluster name |
region |
string | DigitalOcean region (e.g., "nyc3", "sfo3") |
doks_version |
string | Kubernetes version (e.g., "1.27.3-do.0") |
vpc_id |
string | VPC ID where the cluster will be created |
subnets |
object | Cluster and service subnets |
| Variable | Type | Description | Default Value |
|---|---|---|---|
tags |
list(string) | Tags applied to the cluster | [] |
project_id |
string | DigitalOcean project ID | null |
integrations |
object | Cluster integrations | See table below |
cluster_autoscaler_configuration |
object | Autoscaling configuration | {} |
default_pool |
object | Default node pool configuration | See table below |
pools |
map(object) | Additional node pools | {} |
{
registry = bool # Enable Container Registry (default: true)
routing_agent = bool # Enable ingress controller (default: false)
}{
size = string # Machine size (default: "s-1vcpu-1gb")
node_count = number # Number of nodes (default: 1)
tags = optional(list(string)) # Tags for the nodes
labels = optional(map(string)) # Kubernetes labels
taints = optional(list(object({
key = string
value = string
effect = string # "NoSchedule", "PreferNoSchedule", "NoExecute"
})))
}{
"pool-name" = {
size = string # Machine size (required)
min_nodes = number # Minimum nodes (required)
max_nodes = number # Maximum nodes (required)
tags = optional(list(string)) # Tags for the nodes
labels = optional(map(string)) # Kubernetes labels
taints = optional(list(object({
key = string
value = string
effect = string
})))
}
}| Output | Description |
|---|---|
cluster_id |
DOKS cluster ID |
cluster_endpoint |
Cluster API endpoint (sensitive) |
kube_config |
Complete kubeconfig configuration (sensitive) |
node_pool_ids |
IDs of all node pools |
See the examples/basic folder for a simple example of how to use this module.
See the examples/advanced folder for a complete example with multiple pools, autoscaling, and advanced configurations.
-
Subnets: The module requires you to specify subnets (
subnets.clusterandsubnets.services). These must not overlap with your VPC CIDR range. -
Default Pool Autoscaling: The default pool does not have autoscaling enabled automatically. Use additional pools if you need autoscaling.
-
Kubernetes Version: Check the DigitalOcean documentation for available versions in your region.
-
Taints and Tolerations: If you define taints, ensure your pods have the corresponding tolerations.
terraform-do-doks/
├── main.tf # Main resources (cluster and pools)
├── variables.tf # Variable definitions
├── outputs.tf # Module outputs
├── versions.tf # Version requirements
├── README.md # This file
└── examples/
├── basic/ # Basic example
│ ├── main.tf
│ └── terraform.tfvars
└── advanced/ # Advanced example
├── main.tf
└── terraform.tfvars
- Verify that you have a valid DigitalOcean API token
- Check that the region exists and is available
- Ensure the VPC exists and the ID is correct
- Verify that you have specified
taintscorrectly in the pods - Check that
labelsmatch in the pod selectors
This module is available under the MIT license.
To report issues or suggestions, see the project repository.