Skip to content

GKE K8s tutorial

Chris Selzo edited this page Mar 11, 2019 · 20 revisions

Prerequisite steps:

You will need a few tools to interact with GKE, which you can install/setup by performing the following steps:

  1. brew cask install google-cloud-sdk
  2. gcloud components install kubectl
  3. gcloud auth login
  4. Make sure you have docker installed and running - a good way to check is to run docker ps, which should return without error and display at least some columns

Connecting to your GKE cluster

You will be using the kubectl cli to, well, ConTroL your KUBErnetes. Much like the cf cli, it keeps track of config and auth in a file in your home directory, ~/.kube/config. To connect to your cluster (the equivalent of cf api):

  1. gcloud container clusters get-credentials <cluster-name> --zone us-central1-a --project cf-capi-arya
  2. kubectl config current-context will confirm that you are correctly targeted
  3. try running kubectl api-versions, which is roughly the equivalent of cf curl /v2/info

Deploying your first app

Follow along here - notice some familiar terms that mean new things?

It may be nice to run watch 'kubectl get pods -l app=nginx' in another window as you are applying changes, so you can see them happen in "real" time. (side note - recognize the syntax in the -l param? You guessed it, it's a label selector 🎉)

Try scaling the # of replicas: kubectl scale --replicas=10 deployment/nginx-deployment (what does the --current-replicas flag do?)

Before you delete the deployment, check out how kubernetes thinks about revisions:

  1. kubectl rollout history deployment.v1.apps/nginx-deployment
  2. kubectl rollout history deployment.v1.apps/nginx-deployment --revision=1
  3. kubectl rollout history deployment.v1.apps/nginx-deployment --revision=2
  4. You can roll back to revision 1 using the following command: kubectl rollout undo deployment.v1.apps/nginx-deployment && kubectl rollout status deployment.v1.apps/nginx-deployment, which will wait for the rollback to complete before exiting
  5. now run kubectl rollout history deployment.v1.apps/nginx-deployment - where did revision 1 go?
  6. to rollout a specific revision, you can use kubectl rollout undo deployment.v1.apps/nginx-deployment --to-revision=2

For more on deployments in kubernetes, check out https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

Rough cf <-> kubectl mapping

cf rough kubectl equivalent
cf push -f kubectl apply -f
cf apps kubectl get deployments
cf app a kubectl get pods -l app=a
cf delete a kubectl delete deployment a-deployment
cf scale a -i 3 kubectl scale --replicas=3 deployment/a-deployment
cf map-route kubectl expose deployment
Clone this wiki locally