Create new GKE cluster using OCLI

The following document shows how to create a new GKE cluster using OCLI

Prerequisites

  1. Install gcloud >= 2.50 and gke-gcloud-auth-plugin plugin.

  2. You must have a GCP project and a user or serviceaccount having admin privileges. You can log in using the following command.

    gcloud config set project $PROJECT_ID
    
    # gcloud ADC login
    gcloud auth application-default login
    
  3. Enable Service usage API in your project. You can use the below command or use the console for the same.

    gcloud auth login \
      && gcloud services enable serviceusage.googleapis.com --project=$PROJECT_ID
    

πŸ“˜

Suggestion

We highly recommend you to please go through the GCP Infrastructure requirementscarefully.

Installing OCLI

  1. Download the binary using the below command.
    curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/binaries/ocli_$(curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/stable.txt)_darwin_arm64 -o ocli
    
    curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/binaries/ocli_$(curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/stable.txt)_darwin_amd64 -o ocli
    
    curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/binaries/ocli_$(curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/stable.txt)_linux_arm64 -o ocli
    
    curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/binaries/ocli_$(curl -H 'Cache-Control: max-age=0' -s https://releases.ocli.truefoundry.tech/stable.txt)_linux_amd64 -o ocli
    
  2. Make the binary executable and move it to $PATH
    sudo chmod +x ./ocli
    sudo mv ocli /usr/local/bin
    
  3. Confirm by running the command
    ocli --version
    

Configuring input config file

  1. To create a new cluster, you would require your GCP Project ID, Region, and Networkdetails
  2. Run the following command to fill in the inputs interactively
    ocli init-compute-plane
    
  3. For networking, there are two possible configurations:
    1. New network (Recommended) - This creates a new Virtual network for your new cluster.
    2. Existing network - You can enter your existing Virtual network.
  4. Once all the inputs are filled, an input config file with the nametfy-config.yaml would be generated in your current directory. We highly recommend you to once go through the generated config file and tally your inputs. You can also customize the inputs directly by editing the file. Below is the sample for the same:
aws: null
azure: null
binaries:
  terraform:
    binary_path: null
  terragrunt:
    binary_path: null
gcp:
  cluster:
    name: coolml
  network:
    existing: true
    network_name: existing-vnet
    pod_cidr: ""
    service_cidr: ""
    subnet_cidr: ""
    subnet_id: projects/projectID/regions/us-east1/subnetworks/existing-vnet
  project:
    id: projectID
  region:
    availability_zones:
      - us-east1-b
      - us-east1-c
      - us-east1-d
    name: us-east1
  tags: {}
provider: gcp
aws: null
azure: null
binaries:
  terraform:
    binary_path: null
  terragrunt:
    binary_path: null
gcp:
  cluster:
    name: coolml
  network:
    existing: false
    network_name: ""
    pod_cidr: 10.244.0.0/16
    service_cidr: 10.255.0.0/16
    subnet_cidr: 10.10.0.0/16
    subnet_id: ""
  project:
    id: projectID
  region:
    availability_zones:
      - us-west1-a
      - us-west1-b
      - us-west1-c
    name: us-west1
  tags: {}
provider: gcp

Create the cluster

Run the following command to create the GKE cluster.

ocli run --file tfy-config.yaml

This command may take around 30-45 minutes to complete.

Connecting the cluster

  1. Head over to the TrueFoundry platform and log in. If you haven't logged in, then you can sign up here.
  2. Once you have logged in, navigate to Integrations tab from the left panel and click on Setup Cluster.
  3. Give the name of the GKE cluster and select the cluster type as GCP GKE Standard.
  4. Copy the resulting ocli command. This command installs the agent in your GKE cluster which will connect your cluster to the TrueFoundry control plane. The command looks similar to the following:
ocli connect-compute-plane --cloud gcp-gke-standard --control-plane-url https://coolml.truefoundry.tech \
--token xxxxxxx  --tenant coolml
  1. Run the command from the current directory where your tfy-config.yaml is present.

Saving the output file

Once the above command finishes, save the output using the command below:

ocli output --file tfy-config.yaml > output.txt