Set up your environment with tools to easily manage your GKE Kubernetes cluster

kubernets-tools

In this post I will explain how to setup an environment with all the tools you need to manage your K8s project on GKE (Google Container Engine). 

There is nothing better than jumping on a machine and being able to do anything you want without spending hours installing tools or trying to remember passwords. Having a private repo with service credentials combined with a docker image can save you a lot of time, you just need to clone your repository, run the docker container and you are ready to go crazy with kubectl and helm.

There are many docker containers you can use, but for the sake of this tutorial, we are going to use lfaoro gcloud-kubectl-helm docker container

1- Create the repository

Create a private repo or clone the pre-configured repo: 

git clone git@github.com:lbbento/blog-post-k8s-tools.git

2- Create a service account in GKE

  • Click on “Create Service Account”
  • Give it a name and click on “Create”
  • Give it the role of “Kubernetes Engine Admin” and click on “Continue”
  • Create a key in json format. When you are done creating the key the key will be downloaded to your machine. 

3 – Update the private repo with the service account key

(Remember that it should be a private repo)

Now that you have the key downloaded in your computer, replace the content of the file .google/gcp-credentials.json with the content of your json key. 

4- Update the config file with your cluster details

(Remember that it should be a private repo)

Update the environment config file with the details about your cluster.

In the repo you will find the config file: .google/gcp-cluster.env . In this file you are going to provide information about your cluster.  

The account name your have create in step 2.

SERVICE_ACCOUNT=youraccount@developer.gserviceaccount.com

You don’t have to change this if you keep the same file name and just replace the content with your key.

KEYFILE=gcp-credentials.json

This is the name of your custer in GKE.

CLUSTER=yourcluster

This is the name of the zone your cluster is located in GKE.

ZONE=yourzone

This is the name of your project in GKE.

PROJECT=yourproject

5 – Test it

So, you have setup the environment, now every time you need to access your cluster in GKE you just need to run the script in the root folder called:

run.sh

This is going to pull the docker image if you haven’t pulled it before and run it. After that, you are provided with a shell, all you need to do is authenticate to your cluster which is simply done running:

./authenticate.sh

Optional – Install Helm

Helm is already available in the docker image, to deploy it to your cluster, all you have to do is:

.scripts/deploy-helm-server.sh

That is it. Happy coding and thanks.


0 Comments

Leave a comment