google 计算引擎实例创建错误。资源尚未准备好

google 计算引擎实例创建错误。资源尚未准备好

有时,在创建 Google Compute Engine 实例时,我们会收到如下错误:

GaxiosError: The resource 'projects/zoocorder/zones/us-central1-c/disks/job1617338480855vm' is not ready
    at Gaxios._request (/workspace/node_modules/gaxios/build/src/gaxios.js:86:23)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Compute.requestAsync (/workspace/node_modules/google-auth-library/build/src/auth/
) { 

我不确定错误在哪里,因为它被日志查看器截断了。我需要 Google API 并使用计算引擎创建磁盘和带有自定义 docker 映像的映像。

const {google} = require('googleapis');
const compute = google.compute('v1');


  compute.disks.insert(request, function(err, response) {

}
  var instanceCreateRequest = {
    // Project ID for this request.
    project: 'zoocorder',
    // The name of the zone for this request.
    zone: 'us-central1-c',

    resource: {
      "canIpForward": false,
      "deletionProtection": false,
      "description": "",
      "disks": [
        {
          "autoDelete": true,
          "boot": true,
          "deviceName": instanceId ,
          "guestOsFeatures": [
            {
              "type": "UEFI_COMPATIBLE"
            },
            {
              "type": "SEV_CAPABLE"
            },
            {
              "type": "VIRTIO_SCSI_MULTIQUEUE"
            }
          ],
          "interface": "SCSI",
          "mode": "READ_WRITE",
          "source": "projects/[project]/zones/us-central1-c/disks/" + vmid,
          "type": "PERSISTENT"
        }
      ],
      "displayDevice": {
        "enableDisplay": false
      },
      "labels": {
        "container-vm": "cos-stable-81-12871-1174-0"
      },
      "machineType": "projects/[project]/zones/us-central1-c/machineTypes/n1-standard-4",
      "metadata": {
        "items": [
          {
            "key": "gce-container-declaration",
            "value": "spec:\n  containers:\n    - name: " + instanceId + "\n      image: '[image]'\n      stdin: false\n      tty: false\n  restartPolicy: Always\n\n# This container declaration format is not public API and may change without notice. Please\n# use gcloud command-line tool or Google Cloud Console to run Containers on Google Compute Engine."
          },
          {
            "key": "google-logging-enabled",
            "value": "true"
          }
        ]
      },
      "name": instanceId,
      "networkInterfaces": [
        {
          "accessConfigs": [
            {
              "name": "External NAT",
              "networkTier": "PREMIUM",
              "type": "ONE_TO_ONE_NAT"
            }
          ],
          "network": "projects/zoocorder/global/networks/default",
          "subnetwork": "projects/zoocorder/regions/us-central1/subnetworks/default"
        }
      ],
      "reservationAffinity": {
        "consumeReservationType": "ANY_RESERVATION"
      },
      "scheduling": {
        "automaticRestart": true,
        "onHostMaintenance": "MIGRATE",
        "preemptible": false
      },
      "shieldedInstanceConfig": {
        "enableIntegrityMonitoring": true,
        "enableSecureBoot": false,
        "enableVtpm": true
      },
      "serviceAccounts": [
        {
          "email": "[email]@developer.gserviceaccount.com",
          "scopes": [
            "https://www.googleapis.com/auth/cloud-platform",
            'https://www.googleapis.com/auth/compute'
          ]
        }
      ],
      "tags": {
        "items": [
          "http-server",
          "https-server"
        ]
      }},

    auth: authClient,
  };




  compute.instances.insert(instanceCreateRequest, function(err, response) {
    if (err) {
      console.error(err);
      return;
    }

    console.log("err", err);

    listInstances(instanceId, authClient, mdata);


    console.log(JSON.stringify(response, null, 2));

}


检查了磁盘列表,磁盘已创建,但有时无法正确分配实例。有没有办法等到磁盘准备就绪后再分配实例?另外,我似乎没有在错误或响应中看到任何关于错误的提及,所以我不知道什么时候重试。

答案1

自从我们开始以编程方式移除空闲实例以来,这个问题已经不再发生。这可能是 Google 服务的一个问题,或者如果有大量空闲的云计算实例,它会变得混乱。

相关内容