Install Google Cloud SDK on CentOS 8 and Connect GKE Cluster

To install the Google Cloud SDK on CentOS 8, you can follow these steps. The Google Cloud SDK is a set of tools for managing resources and applications hosted on Google Cloud Platform (GCP).

Update the Package Repository:

Open a terminal and run the following command to update the package repository information:

$ sudo dnf update
$ sudo dnf install epel-release

Install Required Dependencies:

The Google Cloud SDK requires some dependencies. Install them using the following command:

$ sudo yum install -y curl python3

This installs ‘curl’ for downloading files and ‘python3’ as Python is required for the SDK.

Download and Install Google Cloud SDK:

a. Download the Google Cloud SDK installer script:

curl https://sdk.cloud.google.com | bash
Performing post processing steps...done.
Update done!

Modify profile to update your $PATH and enable shell command completion?
Do you want to continue (Y/n)?  y
The Google Cloud SDK installer will now prompt you to update an rc file to bring the Google Cloud CLIs into your environment.

Enter a path to an rc file to update, or leave blank to use [/home/asif/.bashrc]:
Backing up [/home/asif/.bashrc] to [/home/asif/.bashrc.backup].
[/home/asif/.bashrc] has been updated.

==> Start a new shell for the changes to take effect.

For more information on how to get started, please visit:
  https://cloud.google.com/sdk/docs/quickstarts

This command will fetch and run the installation script for the Google Cloud SDK.

b. Follow the on-screen instructions to complete the installation. By default, the installer will create a directory called ‘google-cloud-sdk’ in your home directory and add the necessary components.

Initialize the SDK:

After installation, you need to initialize the Google Cloud SDK. Run the following command and follow the prompts:

$ gcloud init
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

You must log in to continue. Would you like to log in (Y/n)?  y

Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/.....

Enter authorization code: mPj9OzRzZLcbSrcrvzaBKOcrrhLZrObG-adhUA2
You are logged in as: [sample@gmail.com].

Pick cloud project to use:
 [1] project-3311
 [2] Enter a project ID
 [3] Create a new project
Please enter numeric choice or text value (must exactly match list item):  1

Your current project has been set to: [kindy-34411].

Do you want to configure a default Compute Region and Zone? (Y/n)?  y

Done

This command will guide you through the setup process, which includes:

  • Logging in with your Google account.
  • Selecting or creating a GCP project.
  • Setting the default configuration, which includes the project ID, region, and zone.

Authentication: You’ll be prompted to authenticate yourself using your Google account credentials. Follow the instructions provided during the authentication process.

Select a Project: You’ll be asked to select or create a GCP project. You can choose an existing project or create a new one.

Set Configuration: Once you’ve selected a project, you can set configuration options like the default region and zone. These settings can be modified later using the gcloud config command.

Verifying Confuguration:

Verify Configuration: After the setup is complete, you can verify your configuration by running:

$ gcloud config list

This command will display the current configuration, including the selected project.

Connecting GCP Project using gcloud Command:

Using gcloud with Your GCP Project: You can now use the gcloud command-line tool to manage resources and services within your GCP project. For example, you can create and manage virtual machines, manage storage buckets, configure services like Google Cloud Pub/Sub, and much more.

Here are a few example commands to get you started:

To list your GCP projects:

$ gcloud projects list

To set a default project if it's not already set:

$ gcloud config set project PROJECT_ID
$ gcloud config set project direct-vese-3722

To list your Compute Engine instances:

$ gcloud compute instances list

Connect with GKE Cluster:

The gcloud container clusters get-credentials command is used to authenticate kubectl, the Kubernetes command-line tool, to a specific Google Kubernetes Engine (GKE) cluster. This allows you to interact with and manage the specified GKE cluster using kubectl. Here’s how to use the command:

$ gcloud container clusters get-credentials CLUSTER_NAME --zone ZONE --project PROJECT_ID
$ gcloud container clusters get-credentials reports-5467546-gke --zone us-central1-a

Sets up the kubectl configuration to work with the specified GKE cluster, including setting cluster credentials, context, and cluster endpoint information.
Associates the kubectl context with the GKE cluster, allowing you to execute kubectl commands against that cluster.

After running this command, you can use kubectl to interact with your GKE cluster. For example, you can list pods, deploy applications, scale resources, and manage your Kubernetes cluster as needed.

Here’s an example of using kubectl to list the pods in the authenticated GKE cluster:

$ kubectl get pods

Make sure you have both the gcloud CLI and kubectl installed and properly configured on your local machine before running these commands. Also, ensure that you have the appropriate IAM permissions in your Google Cloud project to manage the GKE cluster.

Useful Links:

https://kubernetes.io/
https://cloud.google.com/kubernetes-engine

Avatar photo

Asif Khan

Responsible and proactive professional with more than 13 years of experience in IT systems, open source software applications, DevOps, Linux systems, and cloud operations. My main goals are to automate things, keep them safe, and make sure they are strong. I am very good at planning and building the infrastructure for services that people really want. I was drawn to the fast-paced world of cloud computing because it has resources that can be scaled up or down as needed. One of my best skills is being able to use a lot of different DevOps tools to set up, release management, and microservices ecosystems, as well as for provisioning, orchestration, and configuration management.