Monday, August 17, 2020

KOPS setup on GCP(Google Cloud Platform)

 In this post we are going to discuss about the Setup Kubernetes cluster with KOPS on GCP . we have already discussed about what is Kops and how the Kops works in Cloud Computing.

in order to setup Kubernetes cluster by using KOPS on GCP,we needed below configuration setup

Domain Name:

We have seen how to get the Domain name and how we integrated this with AWS.Same way here we have to Integrate with GCP name servers on godaddy account.

GCP Account & google-cloud-sdk setup:

Create a GCP account and register with project , then we can play around the GCP services. in this blog we are going to use the below services to create cluster

Compute Service : To create VM and and install all binaries related to Kubernetes Cluster.

DNS Service  :  To  Create zone and use for DNS.

IAM & Admin : To create  iam service-accounts 'kops-admin' and permissions.

Storage : To Create a storage bucket to store the configuration of Kubernetes cluster


Before going to Compute Service we have to setup the Google SDK to connect GCP resources/Services in your Desktop/Laptop on windows. this is the best way to communicate to our GCP.

google-cloud-sdk setup :

google-cloud-sdk is the CLI which use to connect/update/create/delete on your GCP resources.in my case i have setup the gc-SDK in Windows server. for setup here we go,

Download the Cloud SDK installer using link: https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe and install the SDK.

                    (OR)

Open your Windows Power-shell and execute the below command.

then it will prompt you a setup wizard and follow the  install process steps. and it will take some time.

as soon as it installed configure with our GCP account  as below..

double click on Google Cloud SDK Shell from your desktop short cut and it will open the prompt and initialise GCP platform project by command gcloud init and follow the steps.

                                              Compute Service

create VM and and install all binaries related to Kubernetes Cluster:

Go to Compute Engine service and select VM instances click on Create an instance.

please provide the below details and click on Create.

        Name:  k8s-mgnt-server
        Region & Zone  :  select your own regions & zone , i took : us-cental1   &  us-cental1-a
        Machine configuration :   
                   Machine family  : General-purpose
                   Series  : N1
                   Machine type n1-standard-1 (1 vCPU, 3.75 GB memory)
        Confidential VM service
                    Boot disk   : CentOS 7  ( in my case i have selected the disk as CentOS 7)
        Identity and API access  :
                             Access scopes : Allow full access to all Cloud APIs

        Firewall : click the both the check boxes  Allow HTTP traffic & Allow HTTPS traffic


After creating of VM instance , now connect to the instance, in GCP we do have various ways to connect to the instance, as i said best way is gcloud-sdk. now im going to connect the VM by  gcloud-sdk from my windows cmd, for that go to SSH tab and select the View gcloud command

 and we will get the prompt like below, 

copy the complete command and paste into Windows CMD. if you are running this for first time it will tells you as below. 

So again execute the same command by opening CMD with run as Administrator. then out put as below and it will install all the metadata of account.

Try to execute the Command on Windows CMD, and below is the output

now we have connected the GCP VM which we have created without asking any credentials and pem/ppk files.

Install binaries related to Kubernetes Cluster:

Kops:

wget https://github.com/kubernetes/kops/releases/download/v1.18.0-beta.1/kops-linux-amd64  

chmod 700 kops-linux-amd64

mv kops-linux-amd64 /usr/local/bin/kops

Verify the kops version



kubectl:

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl

chmod 700 kubectl

mv kubectl /usr/local/bin/kubectl

verify the kubectl version --short --client

SSH- Key generation

                                                DNS Service

Integration DNS with your GCP by Cloud DNS Service:

                     in my case 
                                    ZoneName as :   sra1k8s and 
                                     DNS name  :    sra1k8s.xyz 
                                     Zone type   :         Public             

  as soon as crate the Zone we will get the record sets. those are the name servers which we are going to add in godaddy account.and test with command dig NS sra1k8s.xyz


                                                        IAM & Admin

Create service account 'kops-admin' and permissions:

just execute the below commands in the VM instance as below..


gcloud iam service-accounts create kops-admin

gcloud projects add-iam-policy-binding project-project-id --member "serviceAccount:kops-admin@project-project-id.iam.gserviceaccount.com" --role "roles/owner"

Create key (josn file) for 'kops-admin' service account and set 'GOOGLE_APPLICATION_CREDENTIALS' variable. use below command for the same.

gcloud iam service-accounts keys create service-account.json --iam-account kops-admin@project-project-id.iam.gserviceaccount.com

export GOOGLE_APPLICATION_CREDENTIALS="$HOME/service-account.json"



                                          Storage-Service

Create a storage bucket to store the configuration of Kubernetes cluster.just execute the below command

gsutil mb -l us-east1 gs://kops-sra1k8s-state-store-2020


Create Kubernetes cluster:

export PROJECT=`gcloud config get-value project`


We must set KOPS_FEATURE_FLAGS = AlphaAllowGCE to create Kubernetes cluster on GCP using kops.It will unlock the GCE features

export KOPS_FEATURE_FLAGS=AlphaAllowGCE



kops create cluster --name=sra1k8s.xyz --state=gs://kops-sra1k8s-state-store-2020 --zones=us-central1-a --node-count=2 --node-size=n1-standard-2 --master-size=n1-standard-2 --master-volume-size 15 --node-volume-size 10 --dns-zone=sra1k8s.xyz --cloud gce --yes

Validate kops cluster

kops validate cluster --state=gs://kops-sra1k8s-state-store-2020




Simple Pod creation 

Delete pod

Delete cluster

kops delete cluster sra1k8s.xyz --state=gs://kops-sra1k8s-state-store-2020 --yes


No comments:

Post a Comment