Deploying Applications on GKE
Introduction: From Cluster to Running Application
You've successfully created a GKE cluster, but it's currently empty. This lesson will guide you through deploying your first containerized application using a Deployment manifest — a YAML file that declaratively describes everything Kubernetes needs to know to run your application.
We'll dissect the manifest section by section, covering container configuration, environment variables, resource management, and health checks. You'll learn how each section works and why it matters for production deployments. Then, you'll see how to apply the manifest to your cluster and verify that your application is running correctly. We'll also briefly cover imperative kubectl commands that let you make quick changes on the fly. By the end of this lesson, you'll be able to write, apply, and verify a complete Deployment manifest on GKE.
Understanding Kubernetes Deployments
A deployment is a Kubernetes resource that manages a set of identical Pods. Before we go further, let's clarify what a pod is. A Pod is the smallest deployable unit in Kubernetes, and it contains one or more containers that share networking and storage. In most cases, a Pod contains just one container, which is your application. When you create a deployment, Kubernetes creates Pods based on the configuration you provide and ensures that the desired number of Pods are always running.
The reason we use deployments instead of creating Pods directly is that deployments provide several critical features.
- First, they handle replication, meaning you can easily run multiple copies of your application for high availability and load distribution.
- Second, they provide self-healing capabilities. If a
Podcrashes or a node fails, the deployment automatically creates replacementPods. - Third, they enable rolling updates, which means you can update your application to a new version without downtime by gradually replacing old
Podswith new ones. - Fourth, they maintain a history of your deployments, allowing you to roll back to a previous version if something goes wrong.
When you create a deployment, you specify how many replicas you want. A replica is simply a copy of your Pod. If you set replicas to 3, Kubernetes will ensure that exactly three Pods are running at all times. If one Pod crashes, Kubernetes immediately creates a new one to maintain the desired count. If you manually delete a Pod, Kubernetes replaces it. This automatic management is what makes Kubernetes reliable for production workloads.
The deployment also acts as a controller that continuously monitors the actual state of your Pods and compares it to the desired state you declared in your manifest. If there's a difference, the deployment takes action to reconcile them. This control loop is fundamental to how Kubernetes operates. You tell Kubernetes what you want in a YAML file, and Kubernetes figures out how to make it happen and keep it that way.
