Get startedGet started for free

Creating Deployments

1. Creating Deployments

Let’s begin with Deployments, the core method for rolling out containerized applications in GKE. But before defining what a deployment is, it’s important to understand what Pods are. Pods are the smallest deployable unit in Kubernetes. They consist of one or more containers that are tightly coupled and share resources like storage and networking. Pods are ephemeral, which means that they can be created and destroyed as needed. A Deployment is a Kubernetes resource that describes the desired state of Pods. Deployments are managed by a built-in controller. A controller is a continuously running process that monitors the state of an object–or set of objects–running on the cluster, and takes action to ensure that the desired state matches the observed state. Now that we have defined some crucial terminology, let’s describe the deployment process, at a high level. The desired state of a Pod, including characteristics and details about how they should run and handle lifecycle events, is described in the Deployment specification file. After this file is submitted to the Kubernetes control plane, a Deployment controller is created. The controller is responsible for converting the desired state into the current state, and maintaining that desired state over time. During this process, the Deployment also creates and configures a ReplicaSet. The ReplicaSet controller instantiates and maintains a replica version of the Pods specified in the Deployment. So, what details are included within a Deployment? A Deployment object file is written in a YAML format and typically identifies the API version; the kind, which in this case is a Deployment; the name of the Deployment; the number of Pod replicas; a Pod template, which defines the metadata and specifications of each of the Pods in the ReplicaSet; a container image; and a specific port to expose and accept traffic for the container. Deployments exist in three distinct lifecycle states: processing, complete, and failed. The processing state indicates what task is being performed. For example the Deployment may be creating a new ReplicaSet, or scaling a ReplicaSet up or down. The complete state indicates that all new replicas are available and updated to the most current version. It also confirms that any old replicas are not running. And finally, the failed state occurs when the creation of a new ReplicaSet could not be completed. For example, if Kubernetes was unable to surface images for the new Pods, or the user who launched the operation lacks permissions, the failed state will occur. Because Deployments declare the state of Pods, they can be used for Pod management tasks such as updating, rolling back to previous revisions, and scaling or autoscaling. Deployments are designed for stateless applications. A stateless application does not store data or state in a cluster or persistent storage, and can be scaled up or down as needed without impacting the application's functionality. Examples of stateless applications include API servers that provide access to data, and websites that don’t contain dynamic content. So, how do you create a Deployment? The first option is to create a YAML file and use the kubectl apply command to describe the desired state of the Deployment object. This is a declarative method, because you specify the desired state, and then the Kubernetes API server creates the necessary objects to achieve that state. The second option is to use the kubectl create deployment command, which specifies the parameters inline. This is an imperative method because you explicitly create the objects that you want to exist. If you use the kubectl create deployment command, you need to: specify the image and tag to run in the container; how many replicas to launch; which port to expose; which API to use; and whether to save this configuration for future use. Finally, you can create a Deployment through the Google Cloud console. The GKE Workloads menu includes an option to create a Deployment. With this method you can include details such as a container image, environment variables, and initialization commands. The Google Cloud console also gives the option to display the Deployment specifications in YAML format.

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.