Comprehensive Guide to Learning Kubernetes with Google Cloud
January 3, 2025

Comprehensive Guide to Learning Kubernetes with Google Cloud


Introduction to Kubernetes

Kubernetes is an open source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It helps manage workloads efficiently, ensuring high availability and scalability.


Key concepts in Kubernetes

  1. cluster: A set of nodes (machines) running a containerized application.
  2. node: A single machine in a Kubernetes cluster (physical or virtual).
  3. pod: The smallest deployable unit in Kubernetes, containing one or more containers.
  4. Serve: An abstraction that defines a logical set of Pods and the policies for accessing them.
  5. deploy: Manage the desired state of Pods and ReplicaSets.
  6. ConfigMap and Secret: Store configuration data and sensitive information separately.
  7. namespace: Provides a way to divide cluster resources among multiple consumers.
  8. Entrance: Manages external access to services in the cluster, usually HTTP.


Set up Kubernetes on Google Cloud


Step 1: Prerequisites

  gcloud components install kubectl
Enter full screen mode

Exit full screen mode


Step 2: Create a Google Kubernetes Engine (GKE) cluster


Using Google Cloud Console:

  1. Go to Google Kubernetes Engine Page.
  2. Click Create a cluster.
  3. Select the cluster type (for example, Standard or Autopilot).
  4. Configure cluster settings such as number of nodes, machine type, and location (region/region).
  5. Click create Configure the cluster.

Use the command line:

  1. Enable Kubernetes engine API:
   gcloud services enable container.googleapis.com
Enter full screen mode

Exit full screen mode

  1. Create a GKE cluster:
   gcloud container clusters create my-cluster --zone us-central1-a --num-nodes=3
Enter full screen mode

Exit full screen mode

replace my-cluster Use your desired cluster name and us-central1-a with your preferred area.

  1. Authenticate kubectl using clustering:
   gcloud container clusters get-credentials my-cluster --zone us-central1-a
Enter full screen mode

Exit full screen mode


Step 3: Verify the cluster

  kubectl get nodes
Enter full screen mode

Exit full screen mode

  • You should see a list of nodes indicating that the cluster is up and running.


Kubernetes basic operations


1. Deploy the application


Using Google Cloud Console:

  1. Navigate to workload tab in the Kubernetes Engine section.
  2. Click deploy.
  3. Specify the container image (for example, gcr.io/google-samples/hello-app:1.0).
  4. Configure deployment settings (e.g. replicas, namespaces).
  5. Click deploy.

Use kubectl:

  kubectl create deployment hello-app --image=gcr.io/google-samples/hello-app:1.0
Enter full screen mode

Exit full screen mode

  • Expose the deployment as a service:
  kubectl expose deployment hello-app --type=LoadBalancer --port=80 --target-port=8080
Enter full screen mode

Exit full screen mode

  • Get the external IP of the service:
  kubectl get service hello-app
Enter full screen mode

Exit full screen mode

  • Use an external IP to access the application.

2. Extend the application


Using Google Cloud Console:

  1. Go to workload tab.
  2. Click the deployment you want to expand.
  3. Adjust the number of copies and click save.

Use kubectl:

  • Scale the deployment to 3 replicas:
  kubectl scale deployment hello-app --replicas=3
Enter full screen mode

Exit full screen mode

  kubectl get pods
Enter full screen mode

Exit full screen mode


3. Update the application


Using Google Cloud Console:

  1. Go to workload tab.
  2. Click on the deployment you want to update.
  3. Edit the container image to a new version (for example, gcr.io/google-samples/hello-app:2.0).
  4. Click save Start the update.

Use kubectl:

  • Update image version:
  kubectl set image deployment/hello-app hello-app=gcr.io/google-samples/hello-app:2.0
Enter full screen mode

Exit full screen mode

  • Monitor release status:
  kubectl rollout status deployment/hello-app
Enter full screen mode

Exit full screen mode


4. Delete resources


Using Google Cloud Console:

  1. Navigate to workload or Services and entrance tab.
  2. Select the resource you want to delete.
  3. Click delete and confirm.

Use kubectl:

  kubectl delete service hello-app
Enter full screen mode

Exit full screen mode

  kubectl delete deployment hello-app
Enter full screen mode

Exit full screen mode


Advanced themes


ConfigMap and Secret


Using Google Cloud Console:

  1. Go to Configuration mapping or secret tab under Kubernetes Engine.
  2. Click create and fill in the required details.

Use kubectl:

  kubectl create configmap my-config --from-literal=key1=value1
Enter full screen mode

Exit full screen mode

  kubectl create secret generic my-secret --from-literal=password=12345
Enter full screen mode

Exit full screen mode


helm chart

  • Helm is the package manager for Kubernetes.
  • Install the helmet:
  curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
Enter full screen mode

Exit full screen mode

  • Deploy your application using Helm:
  helm repo add bitnami https://charts.bitnami.com/bitnami
  helm install my-release bitnami/nginx
Enter full screen mode

Exit full screen mode


Monitor and record


Using Google Cloud Console:

  1. Go to operations tab in the Cloud Console.
  2. use Indicator browser Monitor cluster performance.
  3. Under access log Logging > Log Browser View system and workload logs.

Using gcloud CLI:

  • Enable logging for your cluster:
  gcloud container clusters update my-cluster --logging=SYSTEM,WORKLOAD --monitoring=SYSTEM
Enter full screen mode

Exit full screen mode


clean up


Using Google Cloud Console:

  1. Navigate to Kubernetes engine Page.
  2. Select the cluster to delete.
  3. Click delete and confirm.

Using gcloud CLI:

  • Delete the GKE cluster to avoid charges:
  gcloud container clusters delete my-cluster --zone us-central1-a
Enter full screen mode

Exit full screen mode


Other resources

By following this guide, you can learn the basics of Kubernetes and effectively use it with Google Cloud both locally and through the Google Cloud Console. Expand your knowledge by exploring advanced features and best practices.

2025-01-03 21:19:25

Leave a Reply

Your email address will not be published. Required fields are marked *