Tuesday, January 3, 2017

How to setup GKE connection on your local

Before we start everything, you need to install gcloud at your local.
The way for installation, you can find in here.

$ 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 (1/1 checks) passed.

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

Your browser has been opened to visit:



You are logged in as: [jwang@swiftstack.com].

Pick cloud project to use:
 [1] distributed-rendering
 [2] summer-optics-152017
Please enter numeric choice or text value (must exactly match list
item):  1

Your current project has been set to: [distributed-rendering].

Do you want to configure Google Compute Engine
(https://cloud.google.com/compute) settings (Y/n)?  Y

Which Google Compute Engine zone would you like to use as project
default?
If you do not specify a zone via a command line flag while working
with Compute Engine resources, the default is assumed.
 [1] asia-east1-b
 [2] asia-east1-a
 [3] asia-east1-c
 [4] asia-northeast1-c
 [5] asia-northeast1-b
 [6] asia-northeast1-a
 [7] europe-west1-d
 [8] europe-west1-b
 [9] europe-west1-c
 [10] us-central1-c
 [11] us-central1-f
 [12] us-central1-a
 [13] us-central1-b
 [14] us-east1-d
 [15] us-east1-c
 [16] us-east1-b
 [17] us-west1-a
 [18] us-west1-b
 [19] Do not set default zone
Please enter numeric choice or text value (must exactly match list
item):  10

Your project default Compute Engine zone has been set to [us-central1-c].
You can change it by running [gcloud config set compute/zone NAME].

Your project default Compute Engine region has been set to [us-central1].
You can change it by running [gcloud config set compute/region NAME].

Created a default .boto configuration file at [/Users/jwang/.boto]. See this file and
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use jwang@swiftstack.com by default
* Commands will reference project `distributed-rendering` by default
* Compute Engine commands will use region `us-central1` by default
* Compute Engine commands will use zone `us-central1-c` by default

Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic -h` to learn about advanced features of the SDK like arg files and output formatting


$ gcloud container clusters get-credentials ffmpeg-cluster \
>     --zone us-central1-c --project distributed-rendering
WARNING: Accessing a Container Engine cluster requires the kubernetes commandline
client [kubectl]. To install, run
  $ gcloud components install kubectl

Fetching cluster endpoint and auth data.
kubeconfig entry generated for ffmpeg-cluster.


$ gcloud components install kubectl


Your current Cloud SDK version is: 137.0.1
Installing components from version: 137.0.1

┌─────────────────────────────────────────────────┐
       These components will be installed.      
├────────────────────────────┬─────────┬──────────┤
            Name            │ Version │   Size  
├────────────────────────────┼─────────┼──────────┤
│ kubectl                                      
│ kubectl (Mac OS X, x86_64) │   1.4.6 │ 13.4 MiB │
└────────────────────────────┴─────────┴──────────┘

For the latest full release notes, please visit:

Do you want to continue (Y/n)?  Y

╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area                             ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: kubectl                                      ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: kubectl (Mac OS X, x86_64)                   ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation          ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.

Update done!

Follow the set up from this link


1.  The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified it should point to a file that defines the credentials. The simplest way to get a credential for this purpose is to create a Service account key in the Google API Console:
3.  From the project drop-down, select your project.
4.  On the Credentials page, select the Create credentials drop-down, then select Service account key.
5.  From the Service account drop-down, select an existing service account or create a new one.
6.  For Key type, select the JSON key option, then select Create. The file automatically downloads to your computer.
7.  Put the *.json file you just downloaded in a directory of your choosing. This directory must be private (you can't let anyone get access to this), but accessible to your web server code.
8.  Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file downloaded.
$ mv ./Downloads/Distributed\ Rendering-0818d5fb7809.json ./Documents/gce/
$ cd ./Documents/gce/
$ pwd
/Users/jwang/Documents/gce
$ export GOOGLE_APPLICATION_CREDENTIALS=/Users/jwang/Documents/gce/Distributed\ Rendering-0818d5fb7809.json
$ env | grep 'GOOGLE_APPLICATION_CREDENTIALS'
GOOGLE_APPLICATION_CREDENTIALS=/Users/jwang/Documents/gce/Distributed Rendering-0818d5fb7809.json
9.If you have installed the Google Cloud SDK on your machine and have run the command gcloud auth application-default login, your identity can be used as a proxy to test code calling APIs from that machine.


$ gcloud beta auth application-default login
You do not currently have this command group installed.  Using it
requires the installation of components: [beta]


Your current Cloud SDK version is: 137.0.1
Installing components from version: 137.0.1

┌─────────────────────────────────────────────┐
     These components will be installed.    
├──────────────────────┬────────────┬─────────┤
         Name           Version      Size 
├──────────────────────┼────────────┼─────────┤
│ gcloud Beta Commands │ 2016.01.12 │ < 1 MiB │
└──────────────────────┴────────────┴─────────┘

For the latest full release notes, please visit:

Do you want to continue (Y/n)?  Y

╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area                             ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud Beta Commands                         ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation          ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.

Update done!

Restarting command:
  $ gcloud beta auth application-default login


The environment variable [GOOGLE_APPLICATION_CREDENTIALS] is set to:
  [/Users/jwang/Documents/gce/Distributed Rendering-0818d5fb7809.json]
Credentials will still be generated to the default location:
  [/Users/jwang/.config/gcloud/application_default_credentials.json]
To use these credentials, unset this environment variable before
running your application.

Do you want to continue (Y/n)?  Y

Your browser has been opened to visit:




Credentials saved to file: [/Users/jwang/.config/gcloud/application_default_credentials.json]

These credentials will be used by any library that requests
Application Default Credentials.

Now try to connect to your GKE cluster, there has "connect" button beside your cluster. Just click it.




$ gcloud container clusters get-credentials ffmpeg-cluster \
>     --zone us-central1-c --project distributed-rendering
Fetching cluster endpoint and auth data.
kubeconfig entry generated for ffmpeg-cluster.

$ kubectl proxy
Starting to serve on 127.0.0.1:8001



No comments:

Post a Comment