nsachin08

GKE Deployment Scripts Guide

Community nsachin08
Updated

Google Cloud MCP Server

GKE Deployment Scripts Guide

This guide provides automated scripts to deploy sample applications to your GKE clusters for testing your GCP tools.

Google Cloud MCP Server

Current Suppported Tools:GKE

Prerequisites

Before running these scripts, you need:

  • Google Cloud SDK (gcloud) - For cluster authentication
  • kubectl - For Kubernetes operations
  • Two GKE Autopilot clusters:
    • autopilot-cluster-1 in us-central1
    • autopilot-cluster-2 in europe-west2

Installation Steps

Step 1: Install Google Cloud SDK

Windows (PowerShell)
# Run PowerShell as Administrator
.\setup-gcloud.ps1

Then initialize gcloud:

gcloud init
macOS/Linux (Bash)
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
gcloud init

Step 2: Install kubectl

gcloud components install kubectl

Step 3: Verify Installations

gcloud --version
kubectl version --client

Usage

Quick Start

Option A: PowerShell (Windows)
# Deploy applications to both clusters
.\deploy-apps.ps1 -ProjectId "your-project-id"

# Or use current gcloud project (if configured)
.\deploy-apps.ps1
Option B: Bash (Linux/macOS)
# Make scripts executable
chmod +x deploy-apps.sh cleanup-deployments.sh

# Deploy applications to both clusters
./deploy-apps.sh "your-project-id"

# Or use current gcloud project
./deploy-apps.sh

What Gets Deployed

Cluster 1 (us-central1)

  1. Nginx (3 replicas)

    • Default namespace
    • Service: LoadBalancer on port 80
  2. WordPress Stack

    • Namespace: wordpress
    • MySQL (1 replica) - Database
    • WordPress (2 replicas) - Web application
    • Services: LoadBalancer on port 80
  3. Monitoring Stack

    • Namespace: monitoring
    • Prometheus (1 replica) - Metrics collection
    • Grafana (1 replica) - Visualization
    • Services: LoadBalancer on ports 9090 & 3000

Cluster 2 (europe-west2)

Same applications deployed for comparison and multi-cluster testing.

Verification Commands

After deployment, monitor the applications:

# Watch all pods across both clusters
kubectl get pods --all-namespaces -w

# Get LoadBalancer external IPs
kubectl get services --all-namespaces

# Check pod distribution
kubectl get pods -o wide --all-namespaces

# View resource usage
kubectl top nodes
kubectl top pods --all-namespaces

# Check deployment replicas
kubectl get deployments --all-namespaces

# View events during deployment
kubectl get events --all-namespaces --sort-by='.lastTimestamp'

Testing Your GCP Tools

Once deployments are complete, test your GCP tools:

# List both clusters
py -c "import asyncio; from src.tools.gke import list_gke_clusters; asyncio.run(list_gke_clusters('-'))"

# Get cluster details
py -c "import asyncio; from src.tools.gke import get_gke_cluster; asyncio.run(get_gke_cluster('us-central1', 'autopilot-cluster-1'))"

# List node pools
py -c "import asyncio; from src.tools.gke import list_gke_node_pools; asyncio.run(list_gke_node_pools('us-central1', 'autopilot-cluster-1'))"

# Get node pool details
py -c "import asyncio; from src.tools.gke import get_gke_node_pool; asyncio.run(get_gke_node_pool('us-central1', 'autopilot-cluster-1', 'default-pool'))"

# Get server config
py -c "import asyncio; from src.tools.gke import get_gke_server_config; asyncio.run(get_gke_server_config('us-central1'))"

Cleanup

When you're done testing, remove all deployments:

PowerShell
.\cleanup-deployments.ps1
Bash
./cleanup-deployments.sh

The cleanup script will:

  • Delete all deployments
  • Delete all services
  • Remove custom namespaces (wordpress, monitoring)
  • Keep the clusters running for future use

Troubleshooting

Issue: "gcloud not found"

Solution: Install Google Cloud SDK (see Step 1 above)

Issue: "kubectl not found"

Solution: Install kubectl with gcloud components install kubectl

Issue: "Cluster credentials failed"

  • Verify cluster names spelling
  • Check you're in the correct Google Cloud project: gcloud config get-value project
  • Switch project: gcloud config set project YOUR_PROJECT_ID

Issue: "CreateContainerError" or "ImagePullBackOff"

  • Wait longer for pods to start (images are large)
  • Check pod logs: kubectl logs <pod-name> -n <namespace>
  • Check events: kubectl describe pod <pod-name> -n <namespace>

Issue: LoadBalancer IP stuck in "Pending"

  • This is normal for GKE. The IP will be assigned within a few seconds to a few minutes
  • Check status: kubectl get services --all-namespaces -w

Customization

To deploy different applications, modify the deployment scripts:

  1. Edit deploy-apps.ps1 or deploy-apps.sh
  2. Change image names, replicas, namespaces as needed
  3. Run the modified script

Example - Deploy a different image:

kubectl create deployment my-app --image=busybox:latest --replicas=2

File Structure

gcpInfra/
├── setup-gcloud.ps1          # Install Google Cloud SDK
├── deploy-apps.ps1           # PowerShell deployment script
├── deploy-apps.sh            # Bash deployment script
├── cleanup-deployments.ps1   # PowerShell cleanup script
└── cleanup-deployments.sh    # Bash cleanup script

Next Steps

  1. Run deployment script
  2. Wait for all pods to be ready
  3. Test your GCP tools
  4. Verify all deployments working correctly
  5. Run cleanup when done

For more information on GKE, visit: https://cloud.google.com/kubernetes-engine/docs

MCP Server · Populars

MCP Server · New