You can create these controller objects using the Kubernetes API or by using
kubectl, a command-line interface to Kubernetes installed by
gcloud. Typically, you build a representation of your
desired Kubernetes controller object as a YAML configuration file, and then use
that file with the Kubernetes API or the
kubectl command-line interface.
Types of workloads
Kubernetes provides different kinds of controller objects that correspond to different kinds of workloads you can run. Certain controller objects are better suited to representing specific types of workloads. The following sections describe some common types of workloads and the Kubernetes controller objects you can create to run them on your cluster, including:
- Stateless applications
- Stateful applications
- Batch jobs
A stateless application does not preserve its state and saves no data to persistent storage — all user and session data stays with the client.
You can create a Kubernetes Deployment to deploy a stateless application on your cluster. Pods created by Deployments are not unique and do not preserve their state, which makes scaling and updating stateless applications easier.
You can create a Kubernetes StatefulSet to deploy a stateful application. Pods created by StatefulSets have unique identifiers and can be updated in an ordered, safe way.
Batch jobs represent finite, independent, and often parallel tasks which run to their completion. Some examples of batch jobs include automatic or scheduled tasks like sending emails, rendering video, and performing expensive computations.
You can create a Kubernetes Job to execute and manage a batch task on your cluster. You can specify the number of Pods that should complete their tasks before the Job is complete, as well as the maximum number of Pods that should run in parallel.
Daemons perform ongoing background tasks in their assigned nodes without the need for user intervention. Examples of daemons include log collectors like Fluentd and monitoring services.
You can create a Kubernetes DaemonSet to deploy a daemon on your cluster. DaemonSets create one Pod per node, and you can choose a specific node to which the DaemonSet should deploy.
Managing workload objects
You can create, manage, and delete objects using imperative and declarative methods. The following sections describe these methods as well as the following the following tools you can use to employ them:
kubectl, the Kubernetes command-line tool installed with Cloud SDK
- GKE Workloads menu in GCP Console
- The GKE REST API and the Kubernetes API
Imperative commands allow you to quickly
create, view, update, and delete objects with
kubectl. These commands are
useful for one-off tasks or for making changes to active objects in a cluster.
Imperative commands are commonly used to operate on live, deployed objects on
kubectl features several verb-driven commands for creating and editing
Kubernetes objects. For example:
run: Generate a new object in the cluster. Unless otherwise specified,
runcreates a Deployment object.
runalso supports several other generators
expose: Create a new Service object to load balance traffic across a set of labelled Pods.
autoscale: Create a new Autoscaler object to automatically horizontally scale a controller object, such as a Deployment.
Imperative commands do not require strong understanding of object schema and do not require configuration files.
Imperative object configuration
Imperative object configuration creates, updates, and deletes objects using configuration files containing fully-defined object definitions. You can store object configuration files in source control systems and audit changes more easily than with imperative commands.
Declarative object configuration
Declarative object configuration operates on
locally-stored configuration files but does not require explicit
definition of the operations to be executed. Instead, operations are
automatically detected per-object by
kubectl. This is useful if you are
working with a directory of configuration files with many different operations.
Declarative object management requires a strong understanding of object
schemas and configuration files.
You can run
to create and updates objects declaratively.
objects by reading the whole live object, calculating the differences, then
merging those differences by sending patch requests to the API server.
After you have deployed a workload using
kubectl or the API, you can use the
GKE Workloads menu in GCP Console
to inspect, manage, and edit workloads running on your clusters.
The menu offers the following features:
- You can use the YAML-based text editor to edit live objects from your web browser
- You can view detailed information about objects, including revision history, recent events and activities, and its managed Pods
- You can easily scale Deployments, Jobs, and StatefulSets
- You can autoscale, trigger rolling updates, and manually scale Deployments from the Actions menu.
- You can use Cloud Shell to inspect, edit, and delete any object.
When you deploy a workload using any of the methods previously described, GKE adds a configuration file to your cluster that represents the object.
Inspecting live configurations
To inspect the live configuration of a deployed object, perform the following steps:
Visit the Google Kubernetes Engine Workloads menu in GCP Console.
Select the desired workload.
- Click YAML.
To inspect the live configuration of a deployed object, run the following command:
kubectl get [OBJECT_TYPE] [OBJECT_NAME] -o yaml
[OBJECT_TYPE] might be
job, or other object
type. For example:
kubectl get deployment my-stateless-app -o yaml