pydo.kubernetes.get_kubeconfig()

Generated on 3 Aug 2026 from pydo version v0.40.0

Usage

client.kubernetes.get_kubeconfig(
    cluster_id="bd5f5959-5e1e-4205-a714-a914373942af",
    expiry_seconds=0,
    type=None,
)
Returns Union[str, JSON]Raises HttpResponseError

Description

This endpoint returns a kubeconfig file in YAML format. It can be used to connect to and administer the cluster using the Kubernetes command line tool, kubectl, or other programs supporting kubeconfig files (e.g., client libraries).

The resulting kubeconfig file uses token-based authentication for clusters supporting it, and certificate-based authentication otherwise. For a list of supported versions and more information, see “How to Connect to a DigitalOcean Kubernetes Cluster”.

To retrieve a kubeconfig file for use with a Kubernetes cluster, send a GET request to /v2/kubernetes/clusters/{cluster_id}/kubeconfig.

Clusters supporting token-based authentication may define an expiration by passing a duration in seconds as a query parameter to /v2/kubernetes/clusters/$K8S_CLUSTER_ID/kubeconfig?expiry_seconds=$DURATION_IN_SECONDS. If not set or 0, then the token will have a 7 day expiry. The query parameter has no impact for other kubeconfig types.

Using an sso kubeconfig type requires doctl to be installed to handle the client side of the OAuth2 flow.

Kubernetes Roles granted to a user are derived from that user’s DigitalOcean role. Predefined roles (Owner, Member, Modifier etc.) have an automatic mapping to Kubernetes roles. Custom roles are not automatically mapped to any Kubernetes roles, and require additional configuration by a cluster administrator.

Parameters

cluster_id string required

A unique ID that can be used to reference a Kubernetes cluster.

Min: 1

expiry_seconds integer optional

The duration in seconds that the returned Kubernetes credentials will be valid. If not set or 0, the credentials will have a 7 day expiry.

Min: 0

Default: 0

type string optional

The type of credentials to return in the kubeconfig. When omitted, the
default credential type for the cluster is used: sso for clusters with SSO enabled, token for clusters without SSO enabled.

One of: token, sso

Request Sample

Show Request Sample
import os
from pydo import Client

client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))

resp = client.kubernetes.get_kubeconfig(cluster_id="da8fda8")

Known Issues

The get_kubeconfig method may fail when deserializing YAML responses. As a workaround, use the underlying HTTP client directly:

from pydo import Client
import os

client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
resp = client.kubernetes._client._pipeline.run(
    client.kubernetes._client._client.format_url(
        "/v2/kubernetes/clusters/{cluster_id}/kubeconfig"
    )
)
print(resp.http_response.text())

More Information

See /v2/kubernetes/clusters/{cluster_id}/kubeconfig in the API reference for additional detail on responses, headers, parameters, and more.

We can't find any results for your search.

Try using different keywords or simplifying your search terms.