community.digitalocean.digital_ocean_kubernetes – Create and delete a DigitalOcean Kubernetes cluster

Note

This plugin is part of the community.digitalocean collection (version 1.11.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.digitalocean.

To use it in a playbook, specify: community.digitalocean.digital_ocean_kubernetes.

New in version 1.3.0: of community.digitalocean

Synopsis

  • Create and delete a Kubernetes cluster in DigitalOcean (and optionally wait for it to be running).

Parameters

Parameter Choices/Defaults Comments
auto_upgrade
boolean
    Choices:
  • no
  • yes
A boolean value indicating whether the cluster will be automatically upgraded to new patch releases during its maintenance window.
maintenance_policy
dictionary
An object specifying the maintenance window policy for the Kubernetes cluster (see table below).
name
string / required
A human-readable name for a Kubernetes cluster.
node_pools
list / elements=dictionary
Default:
[{"auto_scale": false, "count": 1, "labels": {}, "max_nodes": 0, "min_nodes": 0, "name": "worker-pool", "size": "s-1vcpu-2gb", "tags": [], "taints": []}]
An object specifying the details of the worker nodes available to the Kubernetes cluster (see table below).
auto_scale
boolean
    Choices:
  • no
  • yes
A boolean value indicating whether auto-scaling is enabled for this node pool.
count
integer
The number of Droplet instances in the node pool.
labels
dictionary
An object containing a set of Kubernetes labels. The keys are user-defined.
max_nodes
integer
The maximum number of nodes that this node pool can be auto-scaled to.
The value will be 0 if auto_scale is set to false.
min_nodes
integer
The minimum number of nodes that this node pool can be auto-scaled to.
The value will be 0 if auto_scale is set to false.
name
string
A human-readable name for the node pool.
size
string
The slug identifier for the type of Droplet used as workers in the node pool.
tags
list / elements=string
An array containing the tags applied to the node pool.
All node pools are automatically tagged "k8s", "k8s-worker", and "k8s:$K8S_CLUSTER_ID".
taints
list / elements=string
An array of taints to apply to all nodes in a pool.
Taints will automatically be applied to all existing nodes and any subsequent nodes added to the pool.
When a taint is removed, it is removed from all nodes in the pool.
oauth_token
string / required
DigitalOcean OAuth token; can be specified in DO_API_KEY, DO_API_TOKEN, or DO_OAUTH_TOKEN environment variables

aliases: API_TOKEN
region
string
Default:
"nyc1"
The slug identifier for the region where the Kubernetes cluster will be created.

aliases: region_id
return_kubeconfig
boolean
    Choices:
  • no
  • yes
Controls whether or not to return the kubeconfig.
state
string
    Choices:
  • present
  • absent
The usual, present to create, absent to destroy
surge_upgrade
boolean
    Choices:
  • no
  • yes
A boolean value indicating whether surge upgrade is enabled/disabled for the cluster.
Surge upgrade makes cluster upgrades fast and reliable by bringing up new nodes before destroying the outdated nodes.
tags
list / elements=string
A flat array of tag names as strings to be applied to the Kubernetes cluster.
All clusters will be automatically tagged "k8s" and "k8s:$K8S_CLUSTER_ID" in addition to any tags provided by the user.
version
string
Default:
"latest"
The slug identifier for the version of Kubernetes used for the cluster. See the /v2/kubernetes/options endpoint for available versions.
vpc_uuid
string
A string specifying the UUID of the VPC to which the Kubernetes cluster will be assigned.
If excluded, the cluster will be assigned to your account's default VPC for the region.
wait
boolean
    Choices:
  • no
  • yes
Wait for the cluster to be running before returning.
wait_timeout
integer
Default:
600
How long before wait gives up, in seconds, when creating a cluster.

Examples

- name: Create a new DigitalOcean Kubernetes cluster in New York 1
  community.digitalocean.digital_ocean_kubernetes:
    state: present
    oauth_token: "{{ lookup('env', 'DO_API_TOKEN') }}"
    name: hacktoberfest
    region: nyc1
    node_pools:
      - name: hacktoberfest-workers
        size: s-1vcpu-2gb
        count: 3
    return_kubeconfig: yes
    wait_timeout: 600
    register: my_cluster

- name: Show the kubeconfig for the cluster we just created
  debug:
    msg: "{{ my_cluster.data.kubeconfig }}"

- name: Destroy (delete) an existing DigitalOcean Kubernetes cluster
  community.digitalocean.digital_ocean_kubernetes:
    state: absent
    oauth_token: "{{ lookup('env', 'DO_API_TOKEN') }}"
    name: hacktoberfest

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
data
dictionary
changed
A DigitalOcean Kubernetes cluster (and optional kubeconfig)

Sample:
{'kubeconfig': 'apiVersion: v1\nclusters:\n- cluster:\n certificate-authority-data: REDACTED\n server: https://REDACTED.k8s.ondigitalocean.com\n name: do-nyc1-hacktoberfest\ncontexts:\n- context:\n cluster: do-nyc1-hacktoberfest\n user: do-nyc1-hacktoberfest-admin\n name: do-nyc1-hacktoberfest\ncurrent-context: do-nyc1-hacktoberfest\nkind: Config\npreferences: {}\nusers:\n- name: do-nyc1-hacktoberfest-admin\n user:\n token: REDACTED', 'kubernetes_cluster': {'auto_upgrade': False, 'cluster_subnet': '10.244.0.0/16', 'created_at': '2020-09-27T00:55:37Z', 'endpoint': 'https://REDACTED.k8s.ondigitalocean.com', 'id': 'REDACTED', 'ipv4': 'REDACTED', 'maintenance_policy': {'day': 'any', 'duration': '4h0m0s', 'start_time': '15:00'}, 'name': 'hacktoberfest', 'node_pools': [{'auto_scale': False, 'count': 1, 'id': 'REDACTED', 'labels': None, 'max_nodes': 0, 'min_nodes': 0, 'name': 'hacktoberfest-workers', 'nodes': [{'created_at': '2020-09-27T00:55:37Z', 'droplet_id': '209555245', 'id': 'REDACTED', 'name': 'hacktoberfest-workers-3tdq1', 'status': {'state': 'running'}, 'updated_at': '2020-09-27T00:58:36Z'}], 'size': 's-1vcpu-2gb', 'tags': ['k8s', 'k8s:REDACTED', 'k8s:worker'], 'taints': []}], 'region': 'nyc1', 'service_subnet': '10.245.0.0/16', 'status': {'state': 'running'}, 'surge_upgrade': False, 'tags': ['k8s', 'k8s:REDACTED'], 'updated_at': '2020-09-27T01:00:37Z', 'version': '1.18.8-do.1', 'vpc_uuid': 'REDACTED'}}


Authors

  • Mark Mercado (@mamercad)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/digitalocean/digital_ocean_kubernetes_module.html