cloud-builders: kubectl image doesn't support (GKE) regional clusters

Regional Clusters cause challenges for the kubectl image as-is:

  • It’s not possible to interact with these clusters using zone flag (they’re referred to by region)
  • Current clusters require kubectl beta commands

Near-term – since it’s possible folks will create Regional Clusters and then be flummoxed that this image doesn’t work with them – perhaps flag this documentation to state “The image does not currently work with Regional Clusters”

Longer-term – the image will need to accommodate a more general ability to refer to cluster locations

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 22 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Let me make sure I have the correct understanding of what you’re asking for, before I start modifying code.

The kubectl wrapper calls gcloud container clusters get-credentials with the --zone flag, but this is incompatible with Regional Clusters, in two ways:

  1. It would need to pass the --region flag instead, and
  2. It would need to call gcloud beta container clusters get-credentials to be able to pass the --region flag.

If that’s the case, I propose this solution: If the CLOUDSDK_COMPUTE_REGION env var is set, pass it to gcloud beta container clusters get-credentials with --region. If CLOUDSDK_COMPUTE_ZONE is set, pass it as --zone as normal. If both are set, usage+exit. Requisite documentation and examples.

Does that work for you?

Now that Regional Clusters are in GA CLOUDSDK_COMPUTE_ZONE can be set to a region:

steps:
- name: gcr.io/cloud-builders/kubectl
  args:
  - get
  - po
  env:
  - CLOUDSDK_COMPUTE_ZONE=us-central1
  - CLOUDSDK_CONTAINER_CLUSTER=cluster-4

@victortrac sorry sorry – your solution isn’t messy… that we’re forced to find solutions for clusters that present differently depending on whether they’re zonal or regional is what I meant.

Hey Simon,

You could create your own cloud-builder that installs the beta version of kubectl. You could start with the kubectl Dockerfile.