Setup Kubernetes Cluster On GCP Using KOPS
- Open Cloud shell
- Lets first get KOPS binary in place
- Download binaries
curl -Lo kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
- Give permission to KOPSpackage using:
chmod +x ./kops
- Copy KOPS using:
sudo mv ./kops /usr/local/bin/
- Download binaries
- Installing kubectl
- Download kubectl using:
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- Give permission to kubectl package using:
chmod +x ./kubectl
- Copy kubectl using:
sudo mv ./kubectl /usr/local/bin/kubectl
- Download kubectl using:
- Creating a state store
- kops needs a state store, to hold the configuration for your clusters. The simplest configuration for Google Cloud is to store it in a Google Cloud Storage bucket in the same account, so that’s how we’ll start. So, just create an empty bucket – you can use any (available) name
gsutil mb gs://<Name of your choice>
- Further, rather than typing the –state argument every time, it’s much easier to export the KOPS_STATE_STORE environment variable:
export KOPS_STATE_STORE=gs://<Name of bucket defined in step 1>
- kops needs a state store, to hold the configuration for your clusters. The simplest configuration for Google Cloud is to store it in a Google Cloud Storage bucket in the same account, so that’s how we’ll start. So, just create an empty bucket – you can use any (available) name
- Create SSH keys before creating cluster using:
ssh-keygen
- Creating our first cluster
- Lets first set a project in Cloud Shell:
PROJECT=`gcloud config get-value project`
- To unlock the GCE features
export KOPS_FEATURE_FLAGS=AlphaAllowGCE
- kops create cluster creates the Cluster object and InstanceGroup object you’ll be working with in kops:
kops create cluster simple.k8s.local --zones us-central1-a --state ${KOPS_STATE_STORE}/ --project=${PROJECT}
- You can now list the Cluster objects in your kops state store
kops get cluster --state ${KOPS_STATE_STORE}
- Starting it all
kops update cluster simple.k8s.local --yes
- Lets first set a project in Cloud Shell:
- Deleting the cluster
kops delete cluster simple.k8s.local --yes