Search code examples
google-cloud-platformgcp-ai-platform-notebookgcp-notebook

Create Jupyter notebook using gcloud command


I'm trying to create a Jupyter notebook on AI platform (https://cloud.google.com/ai-platform/notebooks/docs/create-new) using devops pipeline and for that i need gcloud command to create a Jupyter notebook but i couldn't find out on GCP documentation. can some one help here?


Solution

  • The command not yet exists. You can create a datalab VM if you want. If you really want to use the notebook out of datalab environment, I dug into it.

    In my browser, I activated the developer mode, I went to network section and I created a notebook instance. I caught this in the post HTTP post

    URL:
    https://clients6.google.com/compute/v1/projects/gbl-imt-homerider-basguillaueb/zones/us-west1-b/instances?key=<API KEY>
    
    Post Content:
    {
      "name": "tensorflow-20190925-144402",
      "machineType": "zones/us-west1-b/machineTypes/n1-standard-4",
      "guestAccelerators": [],
      "metadata": {
        "items": [
          {
            "key": "proxy-mode",
            "value": "service_account"
          }
        ]
      },
      "disks": [
        {
          "boot": true,
          "autoDelete": true,
          "initializeParams": {
            "diskType": "zones/us-west1-b/diskTypes/pd-standard",
            "diskSizeGb": "100",
            "sourceImage": "projects/deeplearning-platform-release/global/images/family/tf-1-14-cu100-notebooks"
          }
        }
      ],
      "scheduling": {
        "onHostMaintenance": "TERMINATE"
      },
      "networkInterfaces": [
        {
          "subnetwork": "https://www.googleapis.com/compute/v1/projects/gbl-imt-homerider-basguillaueb/regions/us-west1/subnetworks/datalab-network",
          "accessConfigs": [
            {
              "name": "external-nat",
              "type": "ONE_TO_ONE_NAT"
            }
          ]
        }
      ],
      "serviceAccounts": [
        {
          "email": "default",
          "scopes": [
            "https://www.googleapis.com/auth/cloud-platform",
            "https://www.googleapis.com/auth/userinfo.email"
          ]
        }
      ],
      "tags": {
        "items": [
          "deeplearning-vm"
        ]
      }
    }
    
    

    I translated this in a gcloud command line. Only the NAT part isn't present, I don't know the impact and how to do this in command line

    gcloud beta compute instances create test --zone=us-west1-b --machine-type="n1-standard-4" \
     --boot-disk-type="pd-standard" --boot-disk-size=100 \
     --image="projects/deeplearning-platform-release/global/images/family/tf-1-14-cu100-notebooks" \
     --metadata="proxy-mode=service_account" --tags=deeplearning-vm --boot-disk-auto-delete \
     --maintenance-policy=TERMINATE --scopes="https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/userinfo.email" 
    

    I tested the deployment, it works and the VM appears in the notebook section. I hope this help.