Search code examples
kubernetesgoogle-kubernetes-engineterraform-provider-gcp

GKE autopilot cluster creation failure


I am trying to create composer environment using terraform in GCP and i could see that its getting failed in one of the project while creating the Kubernetes cluster in autopilot mode; its working fine in other 2 projects where we deployed in the same way.

So i tried to create autopilot kubernetes cluster in manual way as well and we are not able to track what is the issue with it as it shows the below error alone:

k8s cluster creation error

Error while trying it from command line:

gcloud container clusters create-auto test \
    --region europe-west2 \
    --project=project-id 

Note: The Pod address range limits the maximum size of the cluster. Please refer to https://cloud.google.com/kubernetes-engine/docs/how-to/flexible-pod-cidr to learn how to optimize IP address allocation. Creating cluster test in europe-west2... Cluster is being deployed...done.

ERROR: (gcloud.container.clusters.create-auto) Operation [<Operation
 clusterConditions: [<StatusCondition
 canonicalCode: CanonicalCodeValueValuesEnum(UNKNOWN, 2)
 message: 'Failed to create cluster'>]
 detail: 'Failed to create cluster'
 endTime: '2022-05-31T20:00:07.8398558Z'
 error: <Status
 code: 2
 details: []
 message: 'Failed to create cluster'>
 name: 'operation-1654027061293-a14298fa'
 nodepoolConditions: []
 operationType: OperationTypeValueValuesEnum(CREATE_CLUSTER, 1)
 progress: <OperationProgress
 metrics: [<Metric
 intValue: 12
 name: 'CLUSTER_CONFIGURING'>, <Metric
 intValue: 12
 name: 'CLUSTER_CONFIGURING_TOTAL'>, <Metric
 intValue: 9
 name: 'CLUSTER_DEPLOYING'>, <Metric
 intValue: 9
 name: 'CLUSTER_DEPLOYING_TOTAL'>]
 stages: []>
 selfLink: 'https://container.googleapis.com/v1/projects/projectid/locations/europe-west2/operations/operation-1654027061293-a14298fa'
 startTime: '2022-05-31T19:57:41.293067757Z'
 status: StatusValueValuesEnum(DONE, 3)
 statusMessage: 'Failed to create cluster'
 targetLink: 'https://container.googleapis.com/v1/projects/projectid/locations/europe-west2/clusters/test'
 zone: 'europe-west2'>] finished with error: Failed to create cluster

Solution

  • Service account “[email protected]” needs the role Kubernetes Engine Service Agent (roles/container.serviceAgent) which cased the k8s cluster creation to fail; after granting the permissions, we were able to create clusters