
Google Kubernetes Engine Gke in GCP
📌 Google Kubernetes Engine (GKE) in GCP
Google Kubernetes Engine (GKE) is a managed Kubernetes service on Google Cloud Platform (GCP) that allows you to deploy, manage, and scale containerized applications using Kubernetes.
GKE automates the management of Kubernetes clusters, providing features like automatic scaling, monitoring, logging, and robust networking.
✅ Key Features of GKE
Managed Kubernetes: Google handles cluster management, node provisioning, and updates.
Automatic Scaling: Scale pods and nodes dynamically based on demand.
High Availability: Supports multi-zone and regional clusters.
Integrated Monitoring and Logging: Powered by Cloud Monitoring and Cloud Logging.
Multi-Cloud Support: Deploy workloads across multiple regions using Anthos.
Security and Compliance: Includes IAM roles, Workload Identity, and VPC-native clusters.
✅ Use Cases of GKE
Microservices Management: Deploy and manage containerized microservices efficiently.
CI/CD Pipelines: Automate deployments using Cloud Build and GKE.
AI/ML Workloads: Run AI and machine learning models using GPUs and TPUs.
Hybrid and Multi-Cloud: Use Anthos to extend Kubernetes clusters across environments.
Real-Time Data Processing: Deploy data pipelines using Kubernetes jobs.
✅ Types of Clusters in GKE
Cluster Type | Description | Use Case |
---|---|---|
Zonal Cluster | Runs within a single zone. | Development and testing. |
Regional Cluster | Runs across multiple zones for high availability. | Production workloads. |
Autopilot Cluster | Fully managed Kubernetes with automated node management. | Simplified operations for most applications. |
Standard Cluster | Provides manual control over cluster management. | Custom workloads with specific requirements. |
✅ Setting Up Google Kubernetes Engine (GKE)
📌 Step 1: Enable GKE API
Enable the GKE API using the GCP Console or CLI:
gcloud services enable container.googleapis.com
📌 Step 2: Install gcloud CLI
Ensure gcloud CLI
is installed and authenticated:
gcloud auth logingcloud config set project [PROJECT_ID]
Replace
[PROJECT_ID]
with your actual GCP project ID.
✅ Create a Kubernetes Cluster
📌 Option 1: Create Standard Cluster
gcloud container clusters create my-cluster \ --zone us-central1-a \ --num-nodes=3 \ --machine-type=e2-standard-4
--num-nodes=3
: Creates 3 nodes.--machine-type
: Specifies the node type.
📌 Option 2: Create Autopilot Cluster
gcloud container clusters create-auto my-autopilot-cluster \ --region us-central1
Autopilot mode reduces operational complexity by managing nodes for you.
✅ Deploy an Application to GKE
📌 Step 1: Connect to Your Cluster
gcloud container clusters get-credentials my-cluster --zone us-central1-a
Retrieves credentials to access your cluster using
kubectl
.
📌 Step 2: Create a Deployment File
Create a deployment.yaml
file:
apiVersion: apps/v1kind: Deploymentmetadata: name: hello-worldspec: replicas: 3 selector: matchLabels: app: hello-world template: metadata: labels: app: hello-world spec: containers: - name: hello-world image: gcr.io/google-samples/hello-app:1.0 ports: - containerPort: 8080
This deploys a simple hello-world app.
📌 Step 3: Apply the Deployment
kubectl apply -f deployment.yaml
Deploys your application to GKE.
📌 Step 4: Expose the Application
kubectl expose deployment hello-world \ --type=LoadBalancer \ --port=80 \ --target-port=8080
LoadBalancer creates an external IP to access the app.
📌 Step 5: Get the External IP
Access your application using the external IP.
✅ Scaling in GKE
📌 Scale Pods
kubectl scale deployment hello-world --replicas=5
Scales the deployment to 5 replicas.
📌 Enable Cluster Autoscaler
gcloud container clusters update my-cluster \ --enable-autoscaling \ --min-nodes=1 \ --max-nodes=5
Adjusts nodes based on workload.
✅ Monitoring and Logging
Cloud Monitoring: View CPU, memory, and network usage.
Cloud Logging: Track application logs.
📌 View Logs
gcloud logging read "resource.type=k8s_container"
📌 Check Pod Status
kubectl get pods
✅ Managing GKE Clusters
List Clusters:
gcloud container clusters list
Delete Cluster:
gcloud container clusters delete my-cluster --zone=us-central1-a
✅ Best Practices for GKE
Use Autopilot Mode: For reducing operational overhead.
Implement Network Policies: Secure your workloads using Kubernetes Network Policies.
Enable Horizontal Pod Autoscaling: Automatically scale pods based on CPU or memory usage.
Configure Health Checks: Ensure apps are running using Kubernetes liveness and readiness probes.
Use Monitoring and Alerts: Configure alerts using Cloud Monitoring to detect anomalies.
✅ Conclusion
Google Kubernetes Engine (GKE) provides a robust, scalable, and flexible environment for managing containerized applications. With its seamless integration with GCP services, GKE is an ideal solution for deploying production-grade applications.