Provision Cloud Infrastructure Using Google Duet AI
This article helps to create a GKS cluster with Google Duet AI, leveraging Duet AI prompts for guidance in EKS cluster creation.
Join the DZone community and get the full member experience.
Join For FreeDuet AI by Google is an amazing tool for app developers. It uses advanced AI to make coding easier. You can talk to it like you talk to a friend, and it helps you write code, fix problems, and learn coding tricks. It's great for both experienced developers and beginners. Duet AI makes coding feel like a chat, making complex tasks simple and enjoyable.
This article guides you through leveraging Duet AI for the following tasks:
- Explore various Google services that you can use to deploy an app to GKE by asking Duet AI context-based questions.
- Prompt Duet AI to supply commands for deploying a basic app to a GKE cluster.
- Utilize Duet AI to explain and generate shell commands for creating, exploring, and modifying the GKE cluster.
Deploy GKE Cluster
Imagine being an infrastructure admin tasked with establishing the infrastructure for a web application development team. The organization has adopted containers and Kubernetes as standards, prompting the team to seek guidance on running their web application efficiently on Kubernetes within Google Cloud. The team aims to minimize infrastructure management overhead.
1. Log in to the Google Cloud Console.
2. Click on the Duet AI icon in the top-right corner of the Google Cloud console toolbar.
3. Click the Start Chatting button.
4. Enter the following prompt:
How can I run Kubernetes on Google Cloud without having to own management
of nodes and the control plane?
Duet AI should respond with something similar to the following:
To run Kubernetes on Google Cloud without having to own management
of nodes and the control plane, you can use Google Kubernetes Engine (GKE)
in Autopilot mode. In Autopilot mode, Google manages the control
plane and system components for you, and also manages your worker nodes.
Based on the information supplied by Duet AI, it appears that opting for a GKE autopilot cluster aligns with our requirements.
Deploy a GKE Autopilot Cluster
In this step, you instruct Duet AI on the process of deploying a GKE Autopilot cluster.
1. Enter the following prompt:
How do I create a GKE Autopilot cluster?
Duet AI provides guidance on creating a cluster through both the Google Cloud console and the Google Cloud CLI.
What is the command to create a GKE Autopilot cluster in my current project
and in the lab region region named duet-ai-demo using the gcloud CLI?
Duet AI should respond with something similar to the following:
gcloud container clusters create-auto duet-ai-demo --region region
3. Click on the Cloud Shell icon in the Duet AI toolbar.
The command is copied to Cloud Shell.
4. Click Enter to run the command.
When provisioning is complete, the Kubernetes Engine > Clusters page looks like this screenshot:
Deploy a Sample Web Application
After successfully setting up a GKE cluster in Autopilot mode, you've chosen to conduct a test by running a sample web application, which is the one your team plans to deploy on this infrastructure. Internally, you have bookmarked the following container image from Google (us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0) for the purpose of testing a containerized web application:
1. In the Duet AI pane, enter the following prompt, and then click Send:
What is the kubectl command to create a deployment called hello-server
for the image us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0?
Duet AI will respond with something similar to:
To create a deployment called hello-server for the image
us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0,
you can use the following kubectl command:
kubectl create deployment hello-server
--image=us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
Run the kubectl command in the Cloud Shell.
2. With the web server now created, you now decide you want to test out provisioning a load balancer in front of the webserver to expose it to the internet.
In the Duet AI pane, enter the following prompt, and then click Send:
What is the kubectl command to expose this deployment on port 80
and target port 8080 with a load balancer?
Duet AI should respond with something similar to the following:
To expose a deployment called hello-server with a load balancer,
you can use the following kubectl expose command:
kubectl expose deployment hello-server --type LoadBalancer --port 80 --target-port 8080
This will create a Compute Engine load balancer for your container.
The section highlighted in the screen below showcases Duet AI prompting questions and providing answers as specified above.
3. Now, you want to see if the web server is running and serving requests properly. To view your deployed application, you need to retrieve the external IP address from the Kubernetes service you created.
Enter the following prompt:
What is the kubectl command to see
the external IP address associated with this load balancer?
Duet AI should respond with something similar to the following:
To see the external IP associated with a load balancer, you can use the following kubectl command:
kubectl get service hello-server
This will output the name of the service, the type of service,
the cluster IP address, the external IP address, and the ports that
the service is listening on.
The section highlighted in the screen below showcases Duet AI prompting questions and providing answers as specified above.
4. In Cloud Shell, run the command provided by Duet AI.
You should see the hello-app running in the tab.
Conclusion
Duet AI is like a super helper for developers. It makes coding faster and helps them get more done. The easy-to-use interface and quick answers make developers happy and let them work better. Using Duet AI makes going from ideas to making things real much easier. It's like having a friendly assistant that makes coding faster and more productive.
Opinions expressed by DZone contributors are their own.
Comments