Playground with Kubernetes (k8s) in Docker Desktop and real GCP account
Basically, after installing docker, we go to Docker Desktop settings and enable kubernetes there
- Download & install docker, enable kubernetes settings
- Download & install gcloud and kubectl (for this scope, no gcloud needed, but we will keep it here) https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl
- Check what contexts available:
kubectl config get-contexts
- Tell k8s to use docker-desktop cluster:
kubectl config use-context docker-desktop
- Check current context:
kubectl config current-context
- Check actually where config parameters are stored:
cat ~/.kube/config
- Run
kubetcl apply -f app.yml
. You should see deployment and service are created. - Open
localhost:4444
, you should see the website is accessible - Check how the deployment is set up by some kubectl commands:
kubetcl get pods
kubetcl get services
kubectl get deployments
kubetcl describe pods
kubetcl describe services
kubectl describe deployments
- Demo video: https://youtu.be/H9wOCqDeuug
Note that k8s/gcloud have concepts here that might look confused: cluster, namespace, context, node. Asking bard.google.com is what I normally do to understand each of them and the differences. Fairly quick.
Note that I choose the default region for my gcp account is asia-southeast1
- Login gcloud:
gcloud login
. Note that here you will have to fill in a payment method - Create a project in Google Cloud console https://console.cloud.google.com/
- Under Kubernetes Engine tab, create a new autopilot cluster (for quickstart with auto setup from gcp)
- See list projects:
gcloud projects list
- Select a project to be active on:
gcloud config set project hello-world-project-390209
(replace to your project nme) - See list clusters:
gcloud container clusters list
- Generate a link to kubeconfig for this cluster:
gcloud container clusters get-credentials autopilot-cluster-1 --region=asia-southeast1
- Check it:
cat ~/.kube/config
- Change current context of kubernetes to this new cluster:
kubectl config set-context gke_hello-world-project-390209_asia-southeast1_autopilot-cluster-1
- Run
kubetcl apply -f app.yml
. You should see deployment and service are created. - Open
http://34.143.203.89
, you should see the website is accessible. The IP here can be taken from the tab "Kubernetes Engine > Service & Ingress" in Google Cloud console - In the Google Cloud console, delete your cluster.
- Demo video: https://youtu.be/A8En5SjZ17c
MIT. See more at LICENSE file.