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
- Open Google Cloud Console.
- Click on Select a project and create a new project (or use an existing one).
- Enable the Kubernetes Engine API:
- Navigate to APIs & Services > Library.
- Search for Kubernetes Engine API and enable it.
- 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
- In the Google Cloud Console, navigate to the left panel and select Kubernetes Engine.
- Click on Create and choose either Auto Pilot or Standard (configure as needed).
- Select Zonal as the location type.
- Use the Release Channel (default) setting.
- (Optional) Use the Setup Guide from the left menu for guided setup.
- In the Default-pool section, configure:
- Number of Nodes (e.g., 3)
- Machine Configuration:
- Nodes: E2
- E2-micro instance type
- Click Create Cluster.
- Configure
kubectl
to use the cluster:gcloud container clusters get-credentials my-cluster --zone us-central1-a
- Verify the cluster status:
kubectl get nodes
Step 3: Deploy a Pod
- Create a deployment running an Nginx container:
kubectl create deployment niginx --image=nginx
- Check the status of the pod:
Output should show running if successful.kubectl get pods
Step 4: Expose the Deployment
- Expose the deployment as a service:
kubectl expose deployment my-nginx --type=LoadBalancer --port=80
- Get the external IP of the service:
kubectl get services
- Open a web browser and enter the external IP to verify that Nginx is running.
Step 5: Scale the Deployment
- Scale the deployment to 3 replicas:
kubectl scale deployment my-nginx --replicas=3
- Verify the number of pods:
kubectl get pods
Step 6: Clean Up
- Delete the service:
kubectl delete service my-nginx
- Delete the deployment:
kubectl delete deployment my-nginx
- 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
- For referring, search kubectl cheat sheet on Google.
- In Geek of Geeks : https://www.geeksforgeeks.org/kubectl-cheatsheet/
- Run authorization if prompted when executing
kubectl
commands. - To list all nodes:
kubectl get nodes
- To delete a specific pod:
kubectl delete pod [POD_NAME]
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