When saving Kubernetes config from doctl with an existing API token, another token is created . Is this normal?

Let’s say I want to programmatically save the Kubeconfig of my Kubernetes cluster using doctl :

      kubernetes cluster kubeconfig save "$CLUSTER_NAME"

I have at my disposal an Access token. However doing this creates a new API Key on my account, which I don’t understand the reason. Since I am providing a API token why should I create a new one? This may result in creating an excessive number of tokens.

Is this normal? Can we force doctl to use the provided API token throughout the full process?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Is this normal?

Yes! You are seeing this due to a recent change in how DOKS Kubernetes clusters handle authentication. Rather than using certificates, they now use API tokens. This gives team administrators much finer control over how their clusters can be accessed. Rather than a shared certificate that can not be revoked, a token tied to a specific kubeconfig file can be revoked without breaking other users.

You can read more about those changes here:

Can we force doctl to use the provided API token throughout the full process?

I’d love to know a more about your use case. Are you calling this as part of a CI process? If you are able to reuse ~/.config/doctl/cache/exec-credential across CI runs, only one token will be generated and reused until it expires. When a token expires, it will be automatically removed from your account.

To prevent the tokens from being generated all together, you could craft a kubeconfig file using a normal DO API token:

apiVersion: v1
- cluster:
    certificate-authority-data: <CA data>
    server: https://<cluster-id>
  name: do-region-cluster-name
- context:
    cluster: do-region-cluster-name
    user: do-region-cluster-name-admin
  name: do-region-cluster-name
current-context: do-region-cluster-name
kind: Config
preferences: {}
- name: do-region-cluster-name-admin
    token: <a DO api token>