<p>Im trying to get the <code>kubectl</code> running on a VM. I followed the steps given <a href="https://coreos.com/kubernetes/docs/latest/configure-kubectl.html" rel="nofollow">here</a> and can go thru with the installation. I copied my local kubernetes config (from <code>/Users/me/.kube/config</code>) to the VM in the <code>.kube</code> directory. However when I run any command such as <code>kubectl get nodes</code> it returns <code>error: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information</code></p>

<p>Is there a way I can run <code>kubectl</code> on a VM ?</p>

<p>To use kubectl to talk to Google Container Engine cluster in a non-Google VM, you can create a user-managed <a href="https://cloud.google.com/iam/docs/service-accounts" rel="nofollow">IAM Service Account</a>, and use it to authenticate to your cluster:</p>

<pre><code># Set these variables for your project
PROJECT_ID=my-project
SA_NAME=my-new-serviceaccount
SA_EMAIL=$SA_NAME@$PROJECT_ID.iam.gserviceaccount.com
KEY_FILE=~/serviceaccount_key.json

# Create a new GCP IAM service account.
gcloud iam service-accounts create $SA_NAME

# Download a json key for that service account.
gcloud iam service-accounts keys create $KEY_FILE --iam-account $SA_EMAIL

# Give that service account the "Container Engine Developer" IAM role for your project.
gcloud projects add-iam-policy-binding $PROJECT_ID --member serviceAccount:$SA_EMAIL --role roles/container.developer

# Configure Application Default Credentials (what kubectl uses) to use that service account.
export GOOGLE_APPLICATION_CREDENTIALS=$KEY_FILE
</code></pre>

<p>And then go ahead and use kubectl as you normally would.</p>
