gke_setup_ingress_certmanager/GKE cluster creation and cl...

148 lines
5.8 KiB
Markdown
Executable File

# GKE cluster creation and cloud shell access
> https://cloud.google.com/kubernetes-engine/docs/quickstart
> https://rafay.co/the-kubernetes-current/getting-started-with-google-kubernetes-engine-gke-0/
## connect with cloud shell, configure the environment
```
tseed@NieX0:~$ gcloud cloud-shell ssh --authorize-session
Starting your Cloud Shell machine...
Waiting for your Cloud Shell machine to start...done.
Warning: Permanently added '[34.76.250.222]:6000' (RSA) to the list of known hosts.
Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to influenzanet-321116.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
toby_n_seed@cloudshell:~ (influenzanet-321116)$
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud config list project
[core]
project = influenzanet-321116
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud config set project influenzanet-321116
Updated property [core/project].
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud config set compute/zone europe-west2-b
Updated property [compute/zone].
```
## build quick cluster
> API reference
> https://cloud.google.com/sdk/gcloud/reference/container/clusters/create
> available GKE versions
> https://cloud.google.com/kubernetes-engine/versioning
> single zone, multi-zone and regional cluster - we will create a single zone cluster for ease
> https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-zonal-cluster
#### Find the default version and default version for a channel for a channel
```
gcloud container get-server-config --format="yaml(defaultClusterVersion)" --zone europe-west2-b
gcloud container get-server-config --flatten="channels" --filter="channels.channel=REGULAR" --format="yaml(channels.channel,channels.validVersions)" --zone europe-west2-b
```
#### Find versions in regular channel, there are rapid and stable channels
```
gcloud container get-server-config --flatten="channels" --filter="channels.channel=RAPID" --format="yaml(channels.channel,channels.validVersions)" --zone europe-west2-b
```
#### Find valid image types and default image
```
gcloud container get-server-config --format="yaml(validImageTypes)" --zone europe-west2-b
gcloud container get-server-config --format="yaml(defaultImageType)" --zone europe-west2-b
```
#### Find instance types
e2-medium is the smallest recommended size for k8s nodes, this is the default.
```
gcloud compute machine-types list --filter="zone:( europe-west2-a europe-west2-b europe-west2-c )"
gcloud compute machine-types list --filter="zone:( europe-west2-b )"
```
### Create the cluster
The command is as if you'd created a cluster with defaults in a single zone.
It features a smaller ssd disk and only a single node, no scaling by node or pod is enabled.
```
gcloud container clusters create influenzanet \
--release-channel=regular \
--cluster-version=1.20.8-gke.900 \
--image-type=COS \
--num-nodes=1 \
--machine-type=e2-medium \
--disk-size=50GB \
--disk-type=pd-ssd \
--zone=europe-west2-b
```
### Delete the cluster
```
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud config set compute/zone europe-west2-b
Updated property [compute/zone].
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud container clusters list
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
influenzanet europe-west2-b 1.20.8-gke.900 35.234.142.111 e2-medium 1.20.8-gke.900 1 RUNNING
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud container clusters delete influenzanet
The following clusters will be deleted.
- [influenzanet] in [europe-west2-b]
Do you want to continue (Y/n)? y
Deleting cluster influenzanet...⠼
```
## Connect to the cluster and test ability to create workload
```
gcloud cloud-shell ssh --authorize-session
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud config list project
[core]
project = influenzanet-321116
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud config set project influenzanet-321116
Updated property [core/project].
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud container clusters list
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
influenzanet europe-west2-b 1.19.9-gke.1900 34.105.199.155 n1-standard-1 1.19.9-gke.1900 2 RUNNING
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud container clusters describe influenzanet
ERROR: (gcloud.container.clusters.describe) One of [--zone, --region] must be supplied: Please specify location.
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud config set compute/zone europe-west2-b
Updated property [compute/zone].
#display cluster info
toby_n_seed@cloudshell:~ (influenzanet-321116)$ gcloud container clusters describe influenzanet
#set as default cluster
toby_n_seed@cloudshell:~/cluster-management (influenzanet-321116)$ gcloud config set container/cluster influenzanet
Updated property [container/cluster].
#this is where the kubectl json creds file is auto created - very handy
toby_n_seed@cloudshell:~/cluster-management (influenzanet-321116)$ gcloud container clusters get-credentials influenzanet
Fetching cluster endpoint and auth data.
kubeconfig entry generated for influenzanet.
#test connectivity with kubectl
toby_n_seed@cloudshell:~ (influenzanet-321116)$ kubectl cluster-info
Kubernetes control plane is running at https://35.197.223.199
GLBCDefaultBackend is running at https://35.197.223.199/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
KubeDNS is running at https://35.197.223.199/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://35.197.223.199/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
```