-
Notifications
You must be signed in to change notification settings - Fork 364
GKE K8s tutorial
You will need a few tools to interact with GKE, which you can install/setup by performing the following steps:
brew cask install google-cloud-sdk
gcloud components install kubectl
gcloud auth login
- Make sure you have
docker
installed and running - a good way to check is to rundocker ps
, which should return without error and display at least some columns
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
):
gcloud container clusters get-credentials <cluster-name> --zone us-central1-a --project cf-capi-arya
-
kubectl config current-context
will confirm that you are correctly targeted - try running
kubectl api-versions
, which is roughly the equivalent ofcf curl /v2/info
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?)
You may have noticed that by default, your deployment of nginx
is not externally routable. To create a load balancer and expose that nginx
to the internets, you can run:
kubectl expose deployment nginx-deployment --type=LoadBalancer --name=example-nginx-service
-
watch 'kubectl describe services example-service'
until you see anEnsuredLoadBalancer
event - you'll also notice that a new field,LoadBalancer Ingress
appears. - Go to https://: to see your app, live on the internets
For more about services, see https://kubernetes.io/docs/concepts/services-networking/service/
Before you delete the deployment, check out how kubernetes thinks about revisions:
kubectl rollout history deployment.v1.apps/nginx-deployment
kubectl rollout history deployment.v1.apps/nginx-deployment --revision=1
kubectl rollout history deployment.v1.apps/nginx-deployment --revision=2
- 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 - now run
kubectl rollout history deployment.v1.apps/nginx-deployment
- where did revision1
go? - 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/
-
brew tap buildpack/tap && brew install pack
to install the cli -
gcloud auth configure-docker
to tell docker to get creds from your google cloud account to allow you to upload container images to GCR, google's container registry
For now, the only built-in buildpacks are for java and node. Both of these languages exist as sample apps in CATs, so go wild (I only tried it with ~/go/src/github.com/cloudfoundry/cf-acceptance-tests/assets/node
)
See https://cloud.google.com/container-registry/docs/pushing-and-pulling#pushing_an_image_to_a_registry - you'll probably end up with something like gcr.io/cf-capi-arya/node-sample:<YOUR_NAME>
Note that unlike the k8s clusters, we are sharing a container registry for this exercise! Which is why I recommend a tag with your name!!
Using all you've learned so far, figure out how to get dora
up and running by building a docker image containing it, pushing it to GCR, running it on GKE, and exposing it to the internet!
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 |
-
Pipelines
-
Contributing
- Tips and Tricks
- Cloud Controller API v3 Style Guide
- Playbooks
- Development configuration
- Testing
-
Architectural Details
-
CC Resources
- Apps
- Audit Events
- Deployments
- Labels
- Services
- Sidecars
-
Dependencies
-
Troubleshooting
- Ruby Console Script to Find Fields that Cannot Be Decrypted
- Logging database queries in unit tests
- Inspecting blobstore cc resources and cc packages(webdav)
- How to Use USR1 Trap for Diagnostics
- How to Perf: Finding and Fixing Bottlenecks
- How to get access to mysql database
- How To Get a Ruby Heap Dumps & GC Stats from CC
- How to curl v4 internal endpoints with mtls
- How to access Bosh Director console and restore an outdated Cloud Config
- Analyzing Cloud Controller's NGINX logs using the toplogs script
-
k8s
-
Archive