Kubernetes Engine Tutorial
Introduction
Kubernetes Engine, also known as Google Kubernetes Engine (GKE), is a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. With GKE, you can quickly and easily get started with Kubernetes without having to manage the underlying infrastructure.
Prerequisites
Before you start using GKE, make sure you have the following:
- A Google Cloud account.
- Google Cloud SDK installed on your local machine.
- Basic knowledge of Kubernetes concepts.
Setting Up Google Cloud SDK
To interact with GKE, you need to set up the Google Cloud SDK. Follow these steps:
Download and install the Google Cloud SDK:
curl https://sdk.cloud.google.com | bash
Initialize the SDK:
gcloud init
Creating a Kubernetes Cluster
Create a Kubernetes cluster in GKE with the following command:
gcloud container clusters create my-cluster --zone us-central1-a
This command will create a cluster named my-cluster in the us-central1-a zone.
Deploying Applications
Deploy your first application to the Kubernetes cluster. Create a deployment using the following command:
kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0
This command deploys a simple Hello World application.
Exposing the Application
Expose the deployment to the internet using a LoadBalancer service:
kubectl expose deployment hello-server --type=LoadBalancer --port 80 --target-port 8080
This command creates a service that exposes the application on port 80.
Scaling the Application
Scale the number of replicas in your deployment:
kubectl scale deployment hello-server --replicas=3
This command scales the deployment to 3 replicas.
Updating the Application
Update the application to a new version:
kubectl set image deployment/hello-server hello-app=gcr.io/google-samples/hello-app:2.0
This command updates the deployment to use version 2.0 of the Hello World application.
Cleaning Up
To clean up the resources you created, delete the cluster:
gcloud container clusters delete my-cluster --zone us-central1-a
This command deletes the cluster and all associated resources.
Conclusion
In this tutorial, you learned how to set up a Kubernetes cluster using Google Kubernetes Engine, deploy an application, expose it to the internet, scale it, update it, and finally clean up the resources. GKE makes it easy to manage Kubernetes clusters and deploy containerized applications at scale.