Diego
Diego

Reputation: 314

K8S api cloud.google.com not available in GKE v1.16.13-gke.401

I am trying to create a BackendConfig resource on a GKE cluster v1.16.13-gke.401 but it gives me the following error:

unable to recognize "backendconfig.yaml": no matches for kind "BackendConfig" in version "cloud.google.com/v1"

I have checked the available apis with the kubectl api-versions command and cloud.google.com is not available. How can I enable it?

I want to create a BackendConfig whit a custom health check like this:

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: my-backendconfig
spec:
  healthCheck:
    checkIntervalSec: 8
    timeoutSec: 1
    healthyThreshold: 1
    unhealthyThreshold: 3
    type: HTTP
    requestPath: /health
    port: 10257

And attach this BackendConfig to a Service like this:

apiVersion: v1
kind: Service
metadata:
  annotations:
    cloud.google.com/backend-config: '{"default": "my-backendconfig"}'

Upvotes: 2

Views: 969

Answers (1)

PjoterS
PjoterS

Reputation: 14084

As mentioned in the comments, issue was caused due to the lack of HTTP Load Balancing add-on in your cluster.

When you are creating GKE cluster with all default setting, feature like HTTP Load Balancing is enabled.

The HTTP Load Balancing add-on is required to use the Google Cloud Load Balancer with Kubernetes Ingress. If enabled, a controller will be installed to coordinate applying load balancing configuration changes to your GCP project

More details can be found in GKE documentation.

For test I have created Cluster-1 without HTTP Load Balancing add-on. There was no BackendConfig CRD - Custom Resource Definition.

The CustomResourceDefinition API resource allows you to define custom resources. Defining a CRD object creates a new custom resource with a name and schema that you specify. The Kubernetes API serves and handles the storage of your custom resource. The name of a CRD object must be a valid DNS subdomain name.

Without BackendConfig and without cloud apiVersion like below

user@cloudshell:~ (k8s-tests-XXX)$ kubectl get crd | grep backend
user@cloudshell:~ (k8s-tests-XXX)$ kubectl api-versions | grep cloud

I was not able to create any BackendConfig.

user@cloudshell:~ (k8s-tests-XXX) $ kubectl apply -f bck.yaml
error: unable to recognize "bck.yaml": no matches for kind "BackendConfig" in version "cloud.google.com/v1"

To make it work, you have to enable HTTP Load Balancing You can do it via UI or command.

Using UI:

Navigation Menu > Clusters > [Cluster-Name] > Details > Clikc on Edit > Scroll down to Add-ons and expand > Find HTTP load balancing and change from Disabled to Enabled.

or command:

gcloud beta container clusters update <clustername> --update-addons=HttpLoadBalancing=ENABLED --zone=<your-zone>

$ gcloud beta container clusters update cluster-1 --update-addons=HttpLoadBalancing=ENABLED --zone=us-central1-c
WARNING: Warning: basic authentication is deprecated, and will be removed in GKE control plane versions 1.19 and newer. For a list of recommended authentication methods, see: https://cloud.google.com/kubernetes-engine/docs/how-to/api-server-authentication

After a while, when Add-on was enabled:

$ kubectl get crd | grep backend
backendconfigs.cloud.google.com             2020-10-23T13:09:29Z
$ kubectl api-versions | grep cloud
cloud.google.com/v1
cloud.google.com/v1beta1
$ kubectl apply -f bck.yaml 
backendconfig.cloud.google.com/my-backendconfig created

Upvotes: 1

Related Questions