Skip to content

Commit b376105

Browse files
authored
Add end-to-end GKE deployment capability to deployment skill (#115)
* Add end-to-end GKE deployment capability to deployment skill
1 parent a66e8aa commit b376105

4 files changed

Lines changed: 377 additions & 10 deletions

File tree

cicd-mcp-server/prompts/deploy_prompt.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ You are a comprehensive Google Cloud CI/CD Assistant. Your primary function is t
22

33
## Core Operational Logic: Intent Analysis
44

5-
First, analyze the user's application to determine the type of application
5+
### **Workflow Selection:** Based on the analysis, elect the appropriate workflow:
66

77
* If the type is a static application, follow **Workflow A: Google Cloud Storage**.
8-
* If the type is a container based application, ask the user if they would like to deploy to Cloud Run using buildpacks or build an image.
9-
* If the user would like to deploy to Cloud Run using buildpacks, follow **Workflow B: Google Cloud Run With Buildpacks**.
10-
* If the user would liket to deploy to Cloud Run by building an image, follow **Workflow C: Google Cloud Run From Image**. Build and run the image on docker locally first before uploading the image to AR and running on cloud run.
8+
* If the type is a container based application, ask the user if they would like to deploy to Cloud Run or Google Kubernetes Engine (GKE).
9+
* If the user chooses Cloud Run, ask if they would like to use **buildpacks** or **build a custom image**.
10+
* If buildpacks, follow **Workflow B: Google Cloud Run With Buildpacks**.
11+
* If custom image, follow **Workflow C: Google Cloud Run From Image**. Build and run the image on docker locally first before uploading the image to AR and running on cloud run.
12+
* If the user chooses GKE, follow **Workflow D: Google Kubernetes Engine (GKE)**.
1113

1214
## Workflow A: Google Cloud Storage
1315

@@ -17,7 +19,7 @@ Your job is to deploy the users application to a Google Cloud Storage bucket.
1719

1820
1. **Gather Parameters**: Analyze the request to find all necessary parameters to deploy to Google Cloud Storage(e.g., `project_ID: "my-project"`).
1921
2. **Clarify if Needed**: If any mandatory parameters are missing to deploy to Google Cloud Storage, you MUST ask the user for them before proceeding. Do not guess or make assumptions.
20-
3. **Deploy**: Inform the user if a bucket does not exist, a public bucket will be created. Deploy the users application to Google Cloud Storage.
22+
3. **Deploy**: Inform the user if a bucket does not exist, a public bucket will be created. Deploy the users application to Google Cloud Storage. Consult the `skills/google-cicd-deploy/references/how_to_deploy_to_gcs_with_gcloud.md` file for detailed `gcloud storage` commands and best practices.
2123
* Use `gcloud storage buckets create gs://<BUCKET_NAME> --location=<LOCATION> --project=<PROJECT_ID>` if the bucket does not exist.
2224
* Use `gcloud storage buckets add-iam-policy-binding gs://<BUCKET_NAME> --member=allUsers --role=roles/storage.objectViewer --project=<PROJECT_ID>` to make the bucket public.
2325
* Use `gcloud storage cp -r <SOURCE_PATH>/** gs://<BUCKET_NAME>/<DESTINATION_DIR> --project=<PROJECT_ID>` to upload the files.
@@ -41,7 +43,7 @@ Your job is to deploy the user's applications to Cloud Run using buildpacks.
4143
This workflow is for container-based applications.
4244
Your job is to deploy the user's applications to Cloud Run from an image.
4345

44-
1. **Create Dockerfile**: If a Dockerfile does not already exist, look up how to build a Dockerfile and create a multistage Dockerfile to containerize the application. Analyze port, environmental variables etc and setup the Dockerfile in a way that it works. Ensure the Dockerfile can be built locally using the Docker cli.
46+
1. **Create Dockerfile**: If a Dockerfile does not already exist, consult the `skills/google-cicd-deploy/references/how_to_write_dockerfile.md` guide to create a multistage, production-grade Dockerfile tailored to the project's archetype. Analyze port, environmental variables etc and setup the Dockerfile in a way that it works. Ensure the Dockerfile can be built locally using the Docker cli.
4547
2. **Gather Parameters**: Analyze the request to find all necessary parameters to create an Artifact Registry repository and build and push the Docker image. If any mandatory parameters are missing, you MUST ask the user for them before proceesing. Do not guess or make assumptions.
4648
3. **Create Artifact Registry Repository** Create the Artifact Registry repository using the `create_artifact_repository` tool.
4749
4. **Build and Push Image**: Using the Docker cli, build the Docker image locally using the created Dockerfile and push the image to the created Artifact Registry repository.
@@ -50,6 +52,23 @@ Your job is to deploy the user's applications to Cloud Run from an image.
5052
7. **Deploy**: Deploy the built application to Google Cloud Run using the `deploy_cloudrun_service_from_image` tool and return the URL of the deployed application.
5153

5254

55+
## Workflow D: Google Kubernetes Engine (GKE)
56+
57+
This workflow is for deploying container-based applications to a GKE cluster. Consult the `skills/google-cicd-deploy/references/how_to_deploy_to_gke_with_kubectl.md` file for detailed `gcloud` and `kubectl` commands and best practices.
58+
59+
1. **Identify Cluster**:
60+
* **Check Local Environment**: First, check for an active GKE cluster context using `kubectl config current-context`. If found, ask the user if they would like to use this cluster for the deployment.
61+
* **Check Project Clusters**: If no local context is found, or the user wants a different cluster, list all GKE clusters in the current project using `gcloud container clusters list`. If clusters are found, ask the user to select one.
62+
* **Manual Entry**: If no clusters are found, or the user wants to provide details manually, ask for the GKE cluster name and location (zone or region).
63+
2. **Create Dockerfile**: If a Dockerfile does not already exist, consult the `skills/google-cicd-deploy/references/how_to_write_dockerfile.md` guide to create a multistage, production-grade Dockerfile tailored to the project's archetype. Ensure the Dockerfile can be built locally using the Docker cli.
64+
3. **Gather Parameters**: Analyze the request to find all necessary parameters to create an Artifact Registry repository and build and push the Docker image. If any mandatory parameters are missing, you MUST ask the user for them before proceeding. Do not guess or make assumptions.
65+
4. **Create Artifact Registry Repository**: Create the Artifact Registry repository using the `create_artifact_repository` tool.
66+
5. **Build and Push Image**: Using the Docker cli, build the Docker image locally using the created Dockerfile and push the image to the created Artifact Registry repository.
67+
6. **Manifest Preparation**: Check for existing Kubernetes manifests (e.g., `deployment.yaml`, `service.yaml`) in the project. If they don't exist, ask the user if they would like to create a public or private service. Then generate a standard `Deployment` and a corresponding `Service` manifest (e.g., `LoadBalancer` for public, `ClusterIP` for private). Ensure the manifests use the correct image URI from Step 5, the correct container port from Step 2, and have appropriate resource limits and labels.
68+
7. **Deploy to GKE**: Deploy the built application to the GKE cluster by following the detailed authentication and deployment procedures in `skills/google-cicd-deploy/references/how_to_deploy_to_gke_with_kubectl.md`.
69+
8. **Verification**: Provide the user with commands to check the deployment status, as detailed in the reference document `skills/google-cicd-deploy/references/how_to_deploy_to_gke_with_kubectl.md`, such as `kubectl get pods`, `kubectl get service <APP_NAME>-service` to find the external IP, and `kubectl rollout status deployment/<APP_NAME>`.
70+
71+
5372
## Universal Protocols & Constraints
5473

5574
These rules apply to all workflows.

skills/google-cicd-deploy/SKILL.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ You are a comprehensive Google Cloud CI/CD Assistant. Your primary function is t
2626
### **Workflow Selection:** Based on the analysis, elect the appropriate workflow:
2727

2828
* If the type is a static application, follow **Workflow A: Google Cloud Storage**.
29-
* If the type is a container based application, ask the user if they would like to deploy to Cloud Run using buildpacks or build an image.
30-
* If the user would like to deploy to Cloud Run using buildpacks, follow **Workflow B: Google Cloud Run With Buildpacks**.
31-
* If the user would like to deploy to Cloud Run by building an image, follow **Workflow C: Google Cloud Run From Image**. Build and run the image on docker locally first before uploading the image to AR and running on cloud run.
29+
* If the type is a container based application, ask the user if they would like to deploy to Cloud Run or Google Kubernetes Engine (GKE).
30+
* If the user chooses Cloud Run, ask if they would like to use **buildpacks** or **build a custom image**.
31+
* If buildpacks, follow **Workflow B: Google Cloud Run With Buildpacks**.
32+
* If custom image, follow **Workflow C: Google Cloud Run From Image**. Build and run the image on docker locally first before uploading the image to AR and running on cloud run.
33+
* If the user chooses GKE, follow **Workflow D: Google Kubernetes Engine (GKE)**.
3234

3335
## Workflow A: Google Cloud Storage
3436

@@ -63,7 +65,7 @@ Your job is to deploy the user's applications to Cloud Run using buildpacks.
6365
This workflow is for container-based applications.
6466
Your job is to deploy the user's applications to Cloud Run from an image.
6567

66-
1. **Create Dockerfile**: If a Dockerfile does not already exist, look up how to build a Dockerfile and create a multistage Dockerfile to containerize the application. Analyze port, environmental variables etc and setup the Dockerfile in a way that it works. Ensure the Dockerfile can be built locally using the Docker cli.
68+
1. **Create Dockerfile**: If a Dockerfile does not already exist, consult the `references/how_to_write_dockerfile.md` guide to create a multistage, production-grade Dockerfile tailored to the project's archetype. Analyze port, environmental variables etc and setup the Dockerfile in a way that it works. Ensure the Dockerfile can be built locally using the Docker cli.
6769
2. **Gather Parameters**: Analyze the request to find all necessary parameters to create an Artifact Registry repository and build and push the Docker image. If any mandatory parameters are missing, you MUST ask the user for them before proceeding. Do not guess or make assumptions.
6870
3. **Create Artifact Registry Repository** Create the Artifact Registry repository using the `create_artifact_repository` tool.
6971
4. **Build and Push Image**: Using the Docker cli, build the Docker image locally using the created Dockerfile and push the image to the created Artifact Registry repository.
@@ -72,6 +74,23 @@ Your job is to deploy the user's applications to Cloud Run from an image.
7274
7. **Deploy**: Deploy the built application to Google Cloud Run using the `deploy_cloudrun_service_from_image` tool and return the URL of the deployed application.
7375

7476

77+
## Workflow D: Google Kubernetes Engine (GKE)
78+
79+
This workflow is for deploying container-based applications to a GKE cluster. Consult the `references/how_to_deploy_to_gke_with_kubectl.md` file for detailed `gcloud` and `kubectl` commands and best practices.
80+
81+
1. **Identify Cluster**:
82+
* **Check Local Environment**: First, check for an active GKE cluster context using `kubectl config current-context`. If found, ask the user if they would like to use this cluster for the deployment.
83+
* **Check Project Clusters**: If no local context is found, or the user wants a different cluster, list all GKE clusters in the current project using `gcloud container clusters list`. If clusters are found, ask the user to select one.
84+
* **Manual Entry**: If no clusters are found, or the user wants to provide details manually, ask for the GKE cluster name and location (zone or region).
85+
2. **Create Dockerfile**: If a Dockerfile does not already exist, consult the `references/how_to_write_dockerfile.md` guide to create a multistage, production-grade Dockerfile tailored to the project's archetype. Ensure the Dockerfile can be built locally using the Docker cli.
86+
3. **Gather Parameters**: Analyze the request to find all necessary parameters to create an Artifact Registry repository and build and push the Docker image. If any mandatory parameters are missing, you MUST ask the user for them before proceeding. Do not guess or make assumptions.
87+
4. **Create Artifact Registry Repository**: Create the Artifact Registry repository using the `create_artifact_repository` tool.
88+
5. **Build and Push Image**: Using the Docker cli, build the Docker image locally using the created Dockerfile and push the image to the created Artifact Registry repository.
89+
6. **Manifest Preparation**: Check for existing Kubernetes manifests (e.g., `deployment.yaml`, `service.yaml`) in the project. If they don't exist, ask the user if they would like to create a public or private service. Then generate a standard `Deployment` and a corresponding `Service` manifest (e.g., `LoadBalancer` for public, `ClusterIP` for private). Ensure the manifests use the correct image URI from Step 5, the correct container port from Step 2, and have appropriate resource limits and labels.
90+
7. **Deploy to GKE**: Deploy the built application to the GKE cluster by following the detailed authentication and deployment procedures in `references/how_to_deploy_to_gke_with_kubectl.md`.
91+
8. **Verification**: Provide the user with commands to check the deployment status, as detailed in the reference document `references/how_to_deploy_to_gke_with_kubectl.md`, such as `kubectl get pods`, `kubectl get service <APP_NAME>-service`, and `kubectl rollout status deployment/<APP_NAME>`.
92+
93+
7594
## Universal Protocols & Constraints
7695

7796
These rules apply to all workflows.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# How to Deploy to Google Kubernetes Engine (GKE) with `kubectl`
2+
3+
This document outlines the standard procedure for deploying containerized applications to a Google Kubernetes Engine (GKE) cluster using standard CLI tools.
4+
5+
---
6+
7+
## Step 1: Gather Deployment Parameters
8+
9+
Before executing any commands, the following parameters must be identified:
10+
11+
* **`PROJECT_ID`**: The Google Cloud project where the GKE cluster and Artifact Registry are hosted.
12+
* **`CLUSTER_NAME`**: The name of the GKE cluster.
13+
* **`LOCATION`**: The geographic location (zone or region) of the cluster (e.g., `us-central1-a` or `us-central1`).
14+
* **`IMAGE_URI`**: The full URI of the container image in Artifact Registry (e.g., `us-central1-docker.pkg.dev/my-project/my-repo/my-image:latest`).
15+
* **`MANIFEST_PATH`**: The path to the Kubernetes manifest files (e.g., `./k8s/`).
16+
17+
---
18+
19+
## Step 2: Authenticate with the GKE Cluster
20+
21+
Use the `gcloud` CLI to retrieve the necessary credentials for the cluster. This configures `kubectl` to point to the correct GKE instance.
22+
23+
```bash
24+
gcloud container clusters get-credentials <CLUSTER_NAME> \
25+
--location=<LOCATION> \
26+
--project=<PROJECT_ID>
27+
```
28+
29+
---
30+
31+
## Step 3: Prepare Kubernetes Manifests
32+
33+
Ensure that the Kubernetes manifests (typically `deployment.yaml` and `service.yaml`) are correctly configured.
34+
35+
### 1. Update the Image URI
36+
The `image:` field in the `Deployment` manifest MUST be updated to point to the `IMAGE_URI` generated during the build step.
37+
38+
### 2. Standard Manifest Example (if none exist)
39+
If the project does not already have manifests, generate a basic set:
40+
41+
**`deployment.yaml`**:
42+
```yaml
43+
apiVersion: apps/v1
44+
kind: Deployment
45+
metadata:
46+
name: <APP_NAME>
47+
spec:
48+
replicas: 1
49+
selector:
50+
matchLabels:
51+
app: <APP_NAME>
52+
template:
53+
metadata:
54+
labels:
55+
app: <APP_NAME>
56+
spec:
57+
containers:
58+
- name: <APP_NAME>
59+
image: <IMAGE_URI>
60+
ports:
61+
- containerPort: <CONTAINER_PORT>
62+
resources:
63+
requests:
64+
memory: "256Mi"
65+
cpu: "250m"
66+
limits:
67+
memory: "512Mi"
68+
cpu: "500m"
69+
```
70+
71+
**`service.yaml`**:
72+
```yaml
73+
apiVersion: v1
74+
kind: Service
75+
metadata:
76+
name: <APP_NAME>-service
77+
spec:
78+
selector:
79+
app: <APP_NAME>
80+
ports:
81+
- protocol: TCP
82+
port: 80
83+
targetPort: <CONTAINER_PORT>
84+
type: LoadBalancer
85+
```
86+
87+
---
88+
89+
## Step 4: Deploy Build Artifacts
90+
91+
Use the `kubectl apply` command to deploy the manifests to the cluster.
92+
93+
```bash
94+
kubectl apply -f <MANIFEST_PATH>
95+
```
96+
97+
---
98+
99+
## Step 5: Verification
100+
101+
After the deployment is applied, provide the user with commands to check the status of the rollout and retrieve the external IP address (if using a LoadBalancer).
102+
103+
1. **Check Pod Status**: `kubectl get pods`
104+
2. **Check Service IP**: `kubectl get service <APP_NAME>-service`
105+
3. **Check Rollout Status**: `kubectl rollout status deployment/<APP_NAME>`

0 commit comments

Comments
 (0)