Deploying Apps to Google Kubernetes Engine using Cloud Marketplace, Kubectl CLI & Helm Charts.
In this article, you would learn how to setup and deploy applications to a Google Kubernetes Engine (GKE) cluster using the Google Cloud Marketplace, Kubectl CLI, Helm3 Charts .
Although this article is based on containers, I would not be talking about Containers, feel free to read up Robert John’s article on What Are Docker Containers.
This is just meant to enable you get running with GKE as fast as possible.
Other articles in the series would guide you into multiple ways of deploying and managing applications to the GKE cluster you will be creating soon.
Kubernetes (commonly know as k8s) is an open-source container-orchestration system for automating application deployment, scaling, and management. It aims to provide a “platform for automating deployment, scaling, and operations of application containers across clusters of hosts”.
It works with a range of container tools, including Docker. — WikiFor an overview of Kubernetes concepts, see the Kubernetes documentation.
Google Kubernetes Engine (GKE) provides a managed environment for deploying, managing, and scaling your containerized applications using Google infrastructure. The Kubernetes Engine environment consists of multiple machines (specifically Google Compute Engine instances) grouped together to form a container cluster.
Prerequisites
- Create a Google Cloud Platform (GCP) project, or use an existing one.
- Enable the Kubernetes Engine API.
- Install GCloud SDK
Main sections in this article
- Deploying Ready Apps to GKE using Cloud Marketplace
- Deploying Container Images to GKE using Kubectl
- Managing Apps on GKE using Helm Charts
Cluster Orchestration with Kubernetes Engine
Kubernetes Engine clusters are powered by the Kubernetes open source cluster management system. Kubernetes provides the mechanisms through which you interact with your container cluster. You use Kubernetes commands and resources to deploy and manage your applications, perform administration tasks and set policies, and monitor the health of your deployed workloads.
When you run a Kubernetes Engine cluster on GKE, you also gain the benefit of advanced cluster management features that Google Cloud Platform provides. These include:
- Load-balancing for Compute Engine instances.
- Node Pools to designate subsets of nodes within a cluster for additional flexibility.
- Automatic scaling of your cluster’s node instance count.
- Automatic upgrades for your cluster’s node software.
- Node auto-repair to maintain node health and availability.
- Logging and Monitoring with Stackdriver for visibility into your cluster.
Creating a Kubernetes Engine cluster
A GKE cluster consists of at least one cluster master machine and multiple worker machines called nodes. Nodes are Compute Engine virtual machine (VM) instances that run the Kubernetes processes necessary to make them part of the cluster.
To setup a GKE cluster, click here OR navigate as follows on the GCP Console:
Kubernetes Engine > Clusters > Create Cluster
(name: my-cluster, leave other fields as is)
If you are more comfortable using the gcloud tool, the equivalent command for the above is below. Do ensure that you have a default project & zone configured.
gcloud container clusters create my-cluster
Your cluster should be ready in a couple of minutes.
Deploying Ready Apps to GKE using Cloud Marketplace
Google Cloud Marketplace includes container images and configuration files, such as a kubectl
configuration, we'll use it to deploy a Wordpress application to the Google Kubernetes Engine Cluster.
When you deploy an app from Google Cloud Marketplace, the Kubernetes resources are created in your cluster, and you can manage the resources as a group.
To see the Kubenetes applications that you can deploy on your GKE cluster, click here OR navigate as follows on the GCP Console:
Marketplace > Filter by Kubernetes Apps
Search for or select an application, to see its information, including its pricing.
Click on your app of choice > Configure.
Enter a name for your application, then click Deploy.
You can enable a public IP access for accessibility from the extenal world, enable Stackdriver Metrics Exporter for monitoring, and also do check the Terms of Service.
Your application will be deployed, with all the resources created for you.
To manage, edit, or delete your application deployment, do so from the GKE cluster’s Applications page.
You can learn more about Google Cloud Marketplace from its documentation.
Deploying Container Images to GKE using Kubectl
Kubectl is a command line tool for controlling Kubernetes clusters, which allows you to run commands against Kubernetes clusters to deploy applications, inspect and manage cluster resources, or view logs.
We’ll use the kubectl tool to deploy a container image to the Google Kubernetes Engine Cluster.
GKE uses Kubernetes objects to create and manage your cluster’s resources. Kubernetes provides the Deployment object for deploying stateless applications like web servers. Service objects define rules and load balancing for accessing your application from the internet.
To install Kubectl, follow steps described here.
Configure kubectl
After creating your cluster, you need to get authentication credentials to interact with the cluster, you can do with a command line that has both kubectl and gcloud installed.
- Login to Gcloud using:
gcloud auth login
This would open a browser window for you to login. You could also set a default project if you haven’t.
- To configure kubectl to manage your GKE cluster, execute:
gcloud container clusters get-credentials my-cluster
Where my-cluster is the name of the cluster you created earlier.
Creating a deployment
In this step, you would create deployments using the kubectl commands and not by writing YAML configurations.
To create a new deployment on your GKE cluster, run the following command:
kubectl create deployment hello-server — image=gcr.io/google-samples/hello-app:1.0
The command creates a Deployment named hello-server on your configured cluster. The Deployment’s Pod runs the hello-app container image.
Inspect the running Pods by running:
kubectl get pods
Exposing the Deployment
You need to expose it to the internet so that users can access it. You can expose your application by creating a Service, which is a Kubernetes resource that exposes your application to external traffic.
To create a new service on your GKE cluster, run the following command:
kubectl expose deployment hello-server — type=LoadBalancer — port 8080
Inspect the hello-server
Service by running:
kubectl get service hello-server
It might take some minutes for an external IP address to be generated. Run the above command again if the EXTERNAL-IP column is in “pending” status.
To learn more about the Kubectl, check out Overview of kubectl.
Managing Apps on GKE using Helm Charts
Helm is described as a “package manager for Kubernetes”, it is a tool for managing applications that run in the Kubernetes cluster manager.
Helm provides a set of operations that are useful for managing applications, such as: inspect, install, upgrade and delete.
We’ll use Helm to deploy applications to the Google Kubernetes Engine Cluster.
Helm provides the same basic feature set as many of the package managers you may already be familiar with, such as Debian’s apt, or Python’s pip. Helm can: Install software. Automatically install software dependencies. Upgrade software. Configure software deployments. Fetch software packages from repositories
Helm Charts
Helm charts are packages of pre-configured Kubernetes resources that are ready to deploy. It consists of metadata that describes the application, plus the infrastructure needed to operate it in terms of the standard Kubernetes primitives. Each chart references one or more (typically Docker-compatible) container images that contain the application code to be run.
To install Helm v3.X, run the following commands, or check out the docs:
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
The Helm Hub repository contains the documentation and some configuration for the distributed public repository search hosted by Helm.
You would install a Wordpress application using its Helm Chart. You can search for the Wordpress Helm Chart and select bitnami/wordpress.
To add the Bitnami Helm Chart repository that’ll enable use install Wordpress, you need to run the following command:
helm repo add bitnami https://charts.bitnami.com/bitnami
To verify that the repository has been added, run the command:
helm repo list
To install the Wordpress Chart to Helm, run the command:
helm install myblog bitnami/wordpress --version 8.1.4 --set wordpressUsername=admin,wordpressPassword=password
This chart bootstraps a WordPress deployment on your Kubernetes cluster using the Helm package manager.
It also packages the Bitnami MariaDB chart which is required for bootstrapping a MariaDB deployment for the database requirements of the WordPress application.
The above command also sets the WordPress administrator account username and password to admin
and password
respectively. You can learn more about the Bitnami Wordpress Chart and its configuration parameters here.
To get the IP address of your deployed application, you can run the command:
kubectl get service myblog-wordpress
Note that this is in the form of *<application_name>-wordpress* . You can also visit the External IP or Login to *<IP>/admin* with the username and password used earlier.
You can also navigate to Kubernetes Engine > Services & Ingress and see how your application is doing. As seen below.
To uninstall an application, you need to run the following command:
helm delete command
Note that every Kubernetes resource that is tied to that release will be removed.
To learn learn more about Helm, do visit its documentation.