Friday, March 21, 2025

#1 K8S Intro -Lab


GCP Kubernetes Hands-on Lab

Objective

By the end of this lab, students will be able to:

  • Log in to Google Cloud Platform (GCP)
  • Create a Kubernetes cluster using Google Kubernetes Engine (GKE)
  • Deploy and manage nodes
  • Deploy and manage pods
  • Run and expose an application

Prerequisites

  • A Google Cloud Platform (GCP) account
  • Billing enabled for the GCP project
  • Google Cloud SDK installed (or use Google Cloud Shell)
  • Basic understanding of Kubernetes concepts

Step 1: Log in to GCP

  1. Open Google Cloud Console.
  2. Click on Select a project and create a new project (or use an existing one).
  3. Enable the Kubernetes Engine API:
    • Navigate to APIs & Services > Library.
    • Search for Kubernetes Engine API and enable it.
  4. Open Cloud Shell (recommended) or install and configure gcloud CLI:
    gcloud auth login
    gcloud config set project [PROJECT_ID]
    




Step 2: Create a Kubernetes Cluster

  1. In the Google Cloud Console, navigate to the left panel and select Kubernetes Engine.
  2. Click on Create and choose either Auto Pilot or Standard (configure as needed).
  3. Select Zonal as the location type.
  4. Use the Release Channel (default) setting.
  5. (Optional) Use the Setup Guide from the left menu for guided setup.
  6. In the Default-pool section, configure:
    • Number of Nodes (e.g., 3)
    • Machine Configuration:
      • Nodes: E2
      • E2-micro instance type
  7. Click Create Cluster.
  8. Configure kubectl to use the cluster:
    gcloud container clusters get-credentials my-cluster --zone us-central1-a
    
  9. Verify the cluster status:
    kubectl get nodes
    

Step 3: Deploy a Pod

  1. Create a deployment running an Nginx container:
    kubectl create deployment niginx --image=nginx
    
  2. Check the status of the pod:
    kubectl get pods
    
    Output should show running if successful.

Step 4: Expose the Deployment

  1. Expose the deployment as a service:
    kubectl expose deployment my-nginx --type=LoadBalancer --port=80
    
  2. Get the external IP of the service:
    kubectl get services
    
  3. Open a web browser and enter the external IP to verify that Nginx is running.

Step 5: Scale the Deployment

  1. Scale the deployment to 3 replicas:
    kubectl scale deployment my-nginx --replicas=3
    
  2. Verify the number of pods:
    kubectl get pods
    

Step 6: Clean Up

  1. Delete the service:
    kubectl delete service my-nginx
    
  2. Delete the deployment:
    kubectl delete deployment my-nginx
    
  3. Delete the cluster:
    gcloud container clusters delete my-cluster --zone us-central1-a
    

    Note: If you do not delete the cluster and pods, you may continue to incur charges while they are running.


Additional Resources


Conclusion

In this lab, students learned how to create a Kubernetes cluster on GCP, deploy an application, expose it to the internet, scale it, and clean up resources. This provides a basic understanding of Kubernetes operations on Google Cloud.

No comments:

Post a Comment

#1 K8S Intro -Lab

GCP Kubernetes Hands-on Lab Objective By the end of this lab, students will be able to: Log in to Google Cloud Platform (GCP) Create a Kub...