By Hoygen Learn
MR.
Hello, on my first attempt used the default context with doct auth init. Now I am using a different context. If I give:
doctl auth init --context 3di
Using token for context 3di
Validating token... ✔
but then when I do kubectl get pods I get all sort of errors.
kubectl get pods
Error: Unable to initialize DigitalOcean API client: access token is required. (hint: run 'doctl auth init')
13819 memcache.go:265] "Unhandled Error" err="couldn't get current server API group list: Get : getting credentials: exec: executable doctl failed with exit code 1"
So how do I tell kubectl to use the doctl initialized context?
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!
Accepted Answer
Hey Hoygen! 👋
You’re absolutely correct! To make kubectl
work with the desired context, you need to configure the kubeconfig to point to the correct Kubernetes cluster managed by DigitalOcean. Here’s a step-by-step summary:
Run this command to get the list of clusters and their IDs:
doctl kubernetes cluster list
Use this command to save the kubeconfig for your cluster and set the current context:
doctl kubernetes cluster kubeconfig save --set-current-context CLUSTER_ID
This ensures kubectl
uses the correct credentials and context when interacting with your cluster.
To double-check the context is set correctly, run:
kubectl config current-context
You should see the context name associated with your cluster.
Finally, test your connection with:
kubectl get pods
Let me know if you run into any other issues!
- Bobby
ok I think I figured out, but eventually I’ll gladly accept more answers. at first I had to find the desired cluster id:
doctl kubernetes cluster list
and then I had to set the kubectl current context to that cluster ID
doctl kubernetes cluster kubeconfig save --set-current-context CLUSTER_ID
please correct me if I am wrong.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.