In this blog post, I will show you how to deploy a containerized application to a GKE Kubernetes cluster on Google Cloud Platform.
This post, follow up from the previous post, where I deployed a GKE cluster.
Google Kubernetes Service (GKE)
GCP flagship Kubernetes service is called GKE, and it allows us to deploy a managed Kubernetes cluster inside GCP infrastructure.
Our management domain in the Cluster allows us to deploy, workloads, nodes, storage and pods.
Google’s management domain involves managing the underlying infrastructure, and the Kubernetes master nodes also are known as a control plane.
Install Kubectl command-line tool
To deploy apps to GKE, we need to use the Kubectl command-line tool, which allows us to deploy and manage deployment on our Kubernetes cluster.
Make sure you have Cloud SDK installed on your machine before running the below command if you don’t have installed, please install it using my previous post.
If you are using Cloud Shell, you need to run the command below.
gcloud components install kubectl
After installing Kubectl, I will set my project using the following command; in this project, I have my GKE cluster.
gcloud config set project ntweekly
To deploy an app to my Cluster, I will use the YAML file below.
kubectl apply -f deploy.yaml
- name: webserver
- containerPort: 80
We can also use the following command to deploy applications to Kubernetes.
kubectl create deployment webserer2 –image=nginx
In the last step, I will expose the deployment to the internet and make it accessible from everywhere.
To do so, I will use the following command to expose the deployment.
kubectl expose deployment webserver –type=LoadBalancer –port=80
To view the external IP address of the deployment, I will use the following command.
kubectl get service webserver
If I open my browser with the external IP address, I will see the nginx web page.
Kubernetes Engine Console
Back to the GKE console, If I click on Workloads, I will see my deployments and external IP address to access them over the internet.
To delete the service, I will run the following command.
kubectl delete service webserver